From the C standard (C11 6.3.2.1 Lvalues, arrays, and function designators, para 3
):
Except when it is the operand of the sizeof operator, the _Alignof operator, or the
unary & operator, or is a string literal used to initialize an array, an expression that has
type ‘‘array of type’’ is converted to an expression with type ‘‘pointer to type’’ that points
to the initial element of the array object and is not an lvalue.
In other words, when you pass that array to a function, it becomes a pointer to the first element of the array and its size is therefore the size of a pointer.
If you want to treat it as an array within the function, you need to explicitly pass in the size information with something like:
void printArray (int *arr, size_t sz) {
for (size_t i = 0; i < sz; i++)
print ("%d ", arr[i]);
puts ("");
}
:
int xyzzy[] = {3,1,3,1,5,9,2,6,5,3,5,8,9};
printArray (xyzzy, sizeof (xyzzy) / sizeof (*xyzzy));