L
Lawrence Kirby
On Wed, 22 Dec 2004 07:43:21 +0100, Emmanuel Delahaye wrote:
....
It is useful for arrays of arrays e.g.
int arr2[3][10];
int (*p)[10] = &arr2[0];
arr2[0] is an array (with type array of 10 ints) and &arr2[0] is a pointer
to that array (with type pointer to an array of 10 ints, the same as p).
Because of p's type expressions like p[x][y] make sense and with p set up
like this will access the same element as arr2[x][y].
Yes, I could have written just
int (*p)[10] = arr2;
in this case but you can naturally express things like things like
p = &arr2[1];
Lawrence
....
No. It's the address of the array (same value), *but the type is
different*. Actually it has the 'int (*)[10]' type, and can be assigned
to a pointer of the same type:
int arr[10];
int (*p)[10] = &arr;
Is it useful or not is another question.
It is useful for arrays of arrays e.g.
int arr2[3][10];
int (*p)[10] = &arr2[0];
arr2[0] is an array (with type array of 10 ints) and &arr2[0] is a pointer
to that array (with type pointer to an array of 10 ints, the same as p).
Because of p's type expressions like p[x][y] make sense and with p set up
like this will access the same element as arr2[x][y].
Yes, I could have written just
int (*p)[10] = arr2;
in this case but you can naturally express things like things like
p = &arr2[1];
Lawrence