|
|
Array Arguments |
|
Array parameters are handled somewhat differently than simple types.
Arrays are passed by "reference" not by "value".
Modifications to the array in a function will affect the original.
Example
void modarray ( int[] x ) {
x[0] = 5;
}
int main (void) {
int i;
int[] x = {0, 1, 2, 3, 4};
for (i = 0; i < 5; i++) {
printf ("%d ", x[i]);
}
printf("\n");
modarray (x);
for (i = 0; i < 5; i++) {
printf ("%d ", x[i]);
}
printf("\n");
return 0;
}Will produce the following output
0 1 2 3 4
5 1 2 3 4