Skip to main content
In C, an array parameter is a function parameter declared to accept an array, but due to a language mechanic known as array decay, it does not receive a copy of the array. Instead, the compiler automatically converts the array parameter into a pointer to the array’s first element. Consequently, the function operates directly on the original memory addresses rather than a local copy.

Syntax Equivalence

When declaring a function, the compiler treats array notation and pointer notation in the parameter list as strictly identical. The specified size in the brackets is entirely ignored by the compiler.

Memory and the sizeof Illusion

Because the array decays into a pointer, type information regarding the array’s total size is lost across the function boundary. Applying the sizeof operator to an array parameter yields the size of the pointer type (typically 4 or 8 bytes), not the size of the original array.
To resolve this, the array’s length must be explicitly passed as an adjacent parameter:

Multidimensional Array Parameters

Array decay only applies to the first dimension (the outermost bound) of an array. When passing multidimensional arrays, all subsequent dimensions must be explicitly defined in the parameter list. The compiler requires these inner bounds to calculate the correct memory offsets (pointer arithmetic) for element access.

Mutability and the const Qualifier

Because array parameters are implicitly pointers to the original data, any modifications made within the function alter the original array. To enforce read-only semantics and prevent unintended side effects, the const qualifier must be applied to the underlying type.

C99 static Array Indices

Introduced in C99, the static keyword can be placed inside the brackets of an array parameter. This does not change the decay-to-pointer behavior, but it serves as an optimization hint to the compiler, guaranteeing that the passed pointer will never be NULL and will point to an array containing at least the specified number of elements.
Tired of Poor C Skills? Fix That With Deep Grasping!Learn More