-
Consider the C program shown below :
#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);
}
The output of this program is
-
- 12 7 6
- 22 12 11
- 14 6 6
- 7 6 6
- 12 7 6
Correct Option: A
Here X is the global variable so still 5.
Here this is global X whose xy has been changed to 6 so 6 is printed
12 66
First x = 5
Then by function P(&x)
X = 5 +2 = 7
Then by function Q(x)
z = z + x
= 7 + 5 = 12
Here x is global variable so still it is 5.
Return to function P(&x)
Y = 7–1= 6 print x =7
return to main
Print x = 6
Here this is global x whose *y has been changed to 6 so 6 is printed.