Passing an Array v.s. Passing a Single Variable
void func(int a[], int n)
{
a[0] += 1;
++n;
}
main()
{
int b[2] = {0, 0};
int n = 0;
printf("%d %d %d\n",
b[0], b[1], n);
func(b, n);
printf("%d %d %d\n",
b[0], b[1], n);
}
0 0 0
1 0 0
Passing an array is to pass an address.
Passing a single variable is to pass a copy of the value.
This is program
ex6.c
Previous slide
Next slide
Back to first slide
View graphic version