Why sizeof(param_array) is the size of pointer?

A special C rule says that for function parameters, array types are adjusted to pointer types. That means:

int length(int array[]);

is equivalent to

int length(int *array);

So when you compute the sizeof the array you are actually computing the size of the pointer.

(C99, 6.7.5.3p7) “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.”

Leave a Comment