help w/ pointers vs arrays
I'm trying to understand how these things work right now and am running into a question that isn't answered in the book.
suppose that I have something like this: Code:
......... Code:
is this legal? |
char *strtbl[NLINES] ... reserves an array of NLINES char pointers in memory, strtbl is initialized to point to the first element of the array
char **strtbl ... is a pointer to a char pointer, but is not initialized to point anywhere (and no memory is reserved for storing the data array) to make things more visible consider this: typedef char *CPTR; CPTR strtbl[NLINES]; /* reserves array and points to 1st element */ versus typedef char *CPTR; CPTR *strtbl; /* points nowhere */ hope it helps :-) |
that does help. thanks.
is there a way around having the constant? maybe something like: typedef char *CPTR; CPTR *strtbl = malloc( nArraySize * sizeof(*int)); would this allocate space for nArraySize number of int* 's ? |
>typedef char *CPTR;
>CPTR *strtbl = malloc( nArraySize * sizeof(*int)); *int = not correct int * = what you need > would this allocate space for nArraySize number of int* 's ? would allocate space for nArraySize INT pointers, but "strtbl" would point to CHAR pointers, which is probably not what you inteded :-) |
All times are GMT -5. The time now is 12:51 AM. |