int whose(int *p, int i) { return p[i]; }
This code uses p
to point to the beginning of an array of integers,
then index an individual integer using parameter i
. In fact,
int *p;
is interchangeable with int p[]
as a parameter
specifier. int p[]
cannot be used out of the context of parameter
specification, however.
Also, note that C does not pass an array by value. In other words, the following example passes the array by reference, not by value:
int change(int array[5], int i, int v) { array[i] = v; }
Furthermore, most C compilers do not check the size of an array. It is very easy to use an invalid index, be very careful when you access an array, especially when the array is passed as a parameter in a subroutine.