GATE 2017 CS (CS2) – Question 24
What is printed by printxy(1,1)?
void printxy(int x, int y) {
int *ptr;
x=0;
ptr=&x;
y=*ptr;
*ptr=1;
printf("%d,%d",x,y);
}Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (C) 1,0
Explanation
x is set to zero and ptr points to x. Copying *ptr into y makes y zero. Writing one through ptr then changes x alone; y is an independent copied value. The output is 1,0, C.