1

This may sound very silly and stupid.I am tyring to understand the difference between

char *token[32];

and

char token[32];

char token[32] declares token to be character array that can contain 32 characters.

In case of char *token[32],token holds 32 character pointers.What does these pointers point to? Or more specifically it is the responsibility of the user to allocate memory for what the pointers point to.?

liv2hak
  • 14,472
  • 53
  • 157
  • 270

2 Answers2

7

Now char *token[32] declares token to be a pointer to character array that can contain 32 characters.

No. It declares token to be an array of 32 char pointers. In other words, in the first case token holds 32 characters, in the second case, it holds 32 pointers.

If you wanted to declare a pointer to a character array that held 32 characters, you would write

char arr[32];
char (*token)[32] = &arr;
  • +1 No I put it back once you threw in the last pair of decls (actually the *last* decl, which is more important than allot of people first give credit). I actually love reading almost all your answers =P – WhozCraig Dec 20 '12 at 22:36
4
char *token[32];

is an array of 32 char pointers. i.e. The array can be used as:

token[0]=p1;
token[1]=p2;
.....

where p1 and p2 can be of char[] or char* type.

This post may help you understand some more related things other than what asked:

C pointer to array/array of pointers disambiguation

Community
  • 1
  • 1
P.P
  • 117,907
  • 20
  • 175
  • 238