GateAI
Programming in C

GATE CSE 2017 Set 2 · Q14

MCQ1 markEasy

Time

Consider the following function implemented in C:void printxy(int x, int y) { int *ptr; x = 0; ptr = &x; y = *ptr; *ptr = 1; printf("%d,%d",x,y); }The output of invoking printxy(1,1) is

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: C) 1,0

Programming in C

Let's trace the execution of printxy(1, 1) step by step:

  1. Initial values of parameters: x=1x = 1, y=1y = 1.

  2. x = 0;   ⟹  x\implies x becomes 00.

  3. ptr = &x;   ⟹  ptr\implies ptr points to the memory location of xx.

  4. y = *ptr;   ⟹  y\implies y is assigned the value stored at ptr (which is x=0x = 0), so y=0y = 0.

  5. *ptr = 1;   ⟹  \implies the value at the address ptr is updated to 11. Since ptr points to xx, xx becomes 11.

  6. printf("%d,%d", x, y); prints the current values of xx and yy, which are 11 and 00 respectively.

Thus, the output printed is 1,0, corresponding to option (C).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Programming in C previous year question is Q14 of the GATE CSE 2017 Set 2 paper. Find more GATE CSE PYQs on Programming in C in Programming and Data Structures, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Programming in C PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Programming in C in GATE CSE

Programming in C has 74 GATE CSE PYQs across 25 papers from 2011 to 2026. 20 of them are 1-mark MCQs like this one, and GATE CSE 2017 Set 2 has 6.

How GATE tests Programming in C

More from GATE CSE 2017 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2017 Set 2 · Q14 · MCQ

Consider the following function implemented in C: void printxy(int x, int y) { int *ptr; x = 0; ptr = &x; y = *ptr; *ptr = 1; printf("%d,%d",x,y); } The output of invoking printxy(1,1) is

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.