I have a question about a pointer to 2d array. If an array is something like
int a[2][3];
then, is this a pointer to array a
?<
Stricly speaking, no, int (*p)[3] = a;
is not a pointer to a
. It is a pointer to the first element of a
. The first element of a
is an array of three ints. p
is a pointer to an array of three ints.
A pointer to the array a
would be declared thus:
int (*q)[2][3] = &a;
The numeric value of p
and q
are likely (or maybe even required to be) the same, but they are of different types. This will come into play when you perform arithmetic on p
or q
. p+1
points to the second element of array a
, while q+1
points to the memory just beyond the end of array a
.
Remember: cdecl is your friend: int a[2][3], int (*q)[2][3].