Possible Duplicate:
C pointer to array/array of pointers disambiguation
How is char (*p)[4];
different from char *p[4];
?
Possible Duplicate:
C pointer to array/array of pointers disambiguation
How is char (*p)[4];
different from char *p[4];
?
char (*p)[4];
-- declare p as pointer to array 4 of char.char *p[4];
-- declare p as array 4 of pointer to char.char (*p)[4];
: p
is a pointer to a char
array of length 4.
char [4]
points to |
char [4] v
+------+ +------+------+------+------+
| p |------------>| | | | |
+------+ +------+------+------+------+
char char char char
p will point to a char [4] array. Array is not created.
p is intended to be assigned at address of a char [4]
char *p[4];
: p
is an array of length 4, each location of the array is a pointer to char
+------+------+------+------+
p | | | | |
an array +------+------+------+------+
itself | | | |
v v v v
char* char* char* char*
p is an array and will be allocated in stack (if automatic)