If I can add some information on the difference between the above answers.
This - []
has higher precedence than this *
when declaring an array. That combined with the assumption that arrays and pointers are always interchangeable (they are not) catches a lot of people out.
Naively one would assume that int *arr[]
would be a pointer to an array because read from left to right this is a natural assumption.
However it is actually an array of integer pointers. You want a pointer to an array? Tell C so:
int (*arr)[array_size];
by setting your own precedence.
As Carl has explained only answers c
and d
are applicable because in the d
case you already have a pointer to a pointer and in the c
case the array of pointers will decay to a pointer to a pointer when passed as an argument to a function.
If you want a function that will read a
and b
, the signature needs to change to the following:
int funct(int (*array_name)[array_size]);
Note that in the above here you will need to specify the size of the array that the pointer will point to.
Some good answers on two dimensional arrays and pointers to pointers here and here.