Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. 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
    1. 12 7 6
    2. 22 12 11
    3. 14 6 6
    4. 7 6 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.



Your comments will be displayed only after manual approval.