Hi,
I am having problem understand one of the questions in our midterm. It is related to pointers.
Code:
6. What is the output of the following program?
int f(int *x, int y) {
*x += 2; y += 1;
return *x + y;
}
int g(int x, int *y) {
*y = x++;
return x + *y;
}
int main( ) {
int x = 3, y = 4;
printf("%d ",f(&x, y));
printf("%d ",g(x, &y));
printf("%d %d \n",x, y);
return 0;
}
(A) 10 11 5 5 (B) 10 11 6 6 (C) 10 12 5 5 (D) 10 11 6 7
The answer is (A) but I get confused where did 11 come from.
Could someone please help me understand this.
Thanks
Sara