Does "int (*)[]" decay into "int **" in a function parameter? Does "int (*)[]" decay into "int **" in a function parameter? arrays arrays

Does "int (*)[]" decay into "int **" in a function parameter?


Only array types converted to pointer to its first element when passed to a function. a is of type pointer to an array of int, i.e, it is of pointer type and therefore no conversion.

For the prototype

void foo(int a[][10]);

compiler interpret it as

void foo(int (*a)[10]);  

that's because a[] is of array type. int a[][10] will never be converted to int **a. That said, the second para in that answer is wrong and misleading.

As a function parameter, int *a[] is equivalent to int ** this is because a is of array type .


int (*)[] is a pointer to an array of int.

In your example, *a can decay to int*. But sizeof(*a) doesn't do decaying; it is essentially sizeof(int[]) which is not valid.

a can not decay at all (it's a pointer).


N1256 §6.7.5.3/p7-8

7 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.

8 A declaration of a parameter as ‘‘function returning type’’ shall be adjusted to ‘‘pointer to function returning type’’, as in 6.3.2.1.

int (*)[] is "pointer to array of int". Is it "array of type"? No, it's a pointer. Is it "function returning type"? No, it's a pointer. Therefore it does not get adjusted.