GateAI
Programming in C

GATE CSE 2016 Set 1 · Q15

NAT1 markEasy

Time

Consider the following C program.#include<stdio.h> void mystery(int *ptra, int *ptrb) { int *temp; temp = ptrb; ptrb = ptra; ptra = temp; } int main() { int a=2016, b=0, c=4, d=42; mystery(&a, &b); if (a < c) mystery(&c, &a); mystery(&a, &d); printf("%d ", a); }The output of the program is _________ .

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 2016

Programming in C

In the function mystery(int *ptra, int *ptrb), the pointer variables ptra and ptrb are passed by value.

The code inside mystery swaps the local pointer variables themselves rather than the values pointed to by them (i.e., it performs temp = ptrb; ptrb = ptra; ptra = temp; instead of dereferencing them like *temp = *ptrb;).

Therefore, any call to mystery() modifies only local copies of the pointers and has no effect on the variables a, b, c, or d in main().

As a result, the value of a remains 2016 throughout the program execution, and `printf("%d ", a)` prints 2016.

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 Q15 of the GATE CSE 2016 Set 1 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. 16 of them are 1-mark NAT questions like this one, and GATE CSE 2016 Set 1 has 3.

How GATE tests Programming in C

More from GATE CSE 2016 Set 1

Share this solution

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

GateAI solution cardGATE CSE 2016 Set 1 · Q15 · NAT

Consider the following C program. #include void mystery(int *ptra, int *ptrb) { int *temp; temp = ptrb; ptrb = ptra; ptra = temp; } int main() { int a=2016, b=0, c=4, d=42; mystery(&a, &b); if (a The output of the program 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.