# include <stdio.h> # define print(x) printf ("%d", x) int x; void Q(int z) { z += x; print(z); } void P(int *y) { int x = *y+2; Q(x); *y = x-1; print(x);} main(void) { x=5; P(&x); print(x); getchar();} |
The output of this program is
a) 1276
b) 22 12 11
c) 14 6 6
d) 766
a) 1276
b) 22 12 11
c) 14 6 6
d) 766
Answer (a)
Note that main() and Q() are accessing the global variable x. Inside P(), pointer variable y also holds address of global variable x, but x in P() is its P’s own local variable.
No comments:
Post a Comment