This is because by convention a pointer to an array is considered as a qualified pointer to the first element of type in many occasions especially on function passed parameters.
You can consult the ISO/IEC 9899:2011 § 6.7.6.3 Function declarators (including prototypes) - Semantics:
A declaration of a parameter as ‘‘array of type’’ shall be adjusted to
‘‘qualified pointer to type’’, where the type qualifiers (if any) are
those specified within the [ and ] of the array type derivation. If
the keyword static also appears within the [ and ] of the array type
derivation, then for each call to the function, the value of the
corresponding actual argument shall provide access to the first
element of an array with at least as many elements as specified by the
size expression.
But a declaration of type int[][]
instead of int**
is not interchangeable because while the first refers to a 2D array, and it will be silently changed by the compiler to a pointer to the first element of the 2D array, the second means a pointer to pointer of int, that is not compatible with a 2D array.
Sometime people are induced in confusion by pseudo 2D arrays defined dynamically as follows:
int **My_2D_array = malloc(sizeof(int *) * 2); //We are allocating 2 pointers to int
My_2D_array[0] = malloc(sizeof(int)*2); //We allocate the first dimension space
My_2D_array[1] = malloc(sizeof(int)*2); //We allocate the second dimension space
In this case the name My_2D_array
will be referred as the address of the first element of an array of 2 pointers to int, and the use of the []
operator will return the first pointer in the pointers array. Applying again the operator []
onto the pointer just obtained, and again used as the address of the first element of a monodimensional array of int's, will returs an int:
int my_int = My_2D_array[0][1]; //mimics a bidimensional array, but isn't!