GATE | Sudo GATE 2020 Mock III (24 January 2019) | Question 35

Consider the following function implemented in C:

void printxy(int x, int y)
{
    int *ptr;
    ptr = &x;
    y = *ptr;
    *ptr = 1;
    printf("%d,%d", x, y);
} 

The output of the printxy(1, 1) is
(A) 0, 0
(B) 0, 1
(C) 1, 0
(D) 1, 1


Answer: (D)

Explanation: Option (D) 1, 1 is correct.

#include 

void printxy(int x, int y) 
{  
    int *ptr;      
    ptr = &x;        
    y = *ptr;       
    *ptr = 1;       
    printf("%d,%d", x, y);  
}

int main()
{
 int x = 1, y = 1;
 printxy(x,y);
}


Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.