Richard Damon said:
Also note that there is also a type difference in passing a pointer to
the array (as your code is declaring) and passing an array as the
automatically decayed value to a pointer to the first element, as is
normally more commonly done.
Yes. Decay semantics is usually used. I can define
a ragged two-dimensional array using decay semantics:
#include <stdio.h>
int const a0[ 4 ]={ 1, 2, 3, 4 };
int const a1[ 4 ]={ 4, 5, 6, 7 };
int const * const a[ 2 ]={ a0, a1 };
int main()
{ printf( "first number: %d\n", a[ 0 ][ 0 ]);
printf( "%zu rows.\n", sizeof a / sizeof 0[ a ]);
printf( "number of columns is unknown.\n" ); }
. However, it would also be possible, albeit less common,
two use proper array-pointer semantics:
#include <stdio.h>
int const a0[ 4 ]={ 1, 2, 3, 4 };
int const a1[ 4 ]={ 4, 5, 6, 7 };
int const( * const a[ 2 ])[ 4 ]={ &a0, &a1 };
int main()
{ printf( "first number: %d\n",( *a[ 0 ])[ 0 ]);
printf( "%zu rows.\n", sizeof a / sizeof 0[ a ]);
printf( "%zu columns.\n", sizeof *a[ 0 ]/ sizeof 0[ *a[ 0 ]]); }
. The common definition of the parameters of the
program-entry function »main« seems to assume decay
semantics.
This shows that when a real array-pointer is used, code has
to be written specifically for this, like for example:
»( *a[ 0 ])[ 0 ]«.
It seems be possible to omit the parentheses in »( *a[ 0 ])[ 0 ]«.
I am not sure why. But one can always write »0[ *a[ 0 ]]«
without parentheses.