Arrays are effectively passed to functions by reference. The array name evaluates to a pointer to the first element, so the function's parameter has a type of ‘pointer-to-element-type’. For example, given the function:
void fill_array_with_square_numbers(int *first, int length) { int i; for (i = 0; i < length; i++) first[i] = i * i; }
…we could write code such as:
int squares[4], moresquares[10]; void fill_array_with_square_numbers(int *first, int length); fill_array_with_square_numbers(squares, 4); fill_array_with_square_numbers(moresquares + 2, 7);
The second call only fills part of the array
moresquares
.
Note that the programmer must take steps to indicate the length of the array, in this case by defining the function to take a length argument. (An alternative would be to identify a special value within the array to mark its end.) The second call only has elements 2 to 8 set (an array of length 7).