The GATE Grind

GATE 2017 CS (CS2) – Question 24

Programming and Data Structures · Programming in C · 1 mark · Multiple choice

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);
}
  1. 0,0
  2. 0,1
  3. 1,0
  4. 1,1

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.

More Programming in C questions

All Programming in C questions →