Give the output of the following program written in C syntax using the four parameter passing methods discussed in section 10.3
int i
int a[2];
void p(int x, int y)
{ x++;
i++;
y++;
}
main()
{ a[0] = 1;
a[1] = 1;
i = 0;
p(a[i],a[i]);
printf("%d\n",a[0]);
printf("%d\n",a[1]);
return 0;
}
It prints:
1
1
it doesn't increment the values as one might think because they're passed by value, not by reference
No comments:
Post a Comment