GateAI
Programming in C

GATE CSE 2026 Set 2 · Q60

NAT2 marksEasy

Time

Consider the following ANSI-C program.#include <stdio.h> int main(){ int *ptr, a, b, c; a=5; b=11; c=20; ptr=&a; *ptr=c; ptr=&c; a=*(&b); c=*ptr-a; printf("%d",c); return(0); }The output of this program is ________. (answer in integer) Note: Assume that the program compiles and runs successfully.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 9

Programming in C

Let us trace the program step by step:

  1. int *ptr, a, b, c; Declares an integer pointer ptr and three integer variables a, b, and c.

  2. a=5; b=11; c=20;

    • a=5a = 5

    • b=11b = 11

    • c=20c = 20

  3. ptr=&a;ptr points to the address of a.

  4. *ptr=c; Assigns the value of c (2020) to the location pointed to by ptr (variable a).

    • Now, a=20a = 20.

  5. ptr=&c;ptr now points to the address of c.

  6. a=*(&b); Dereferencing the address of b yields the value of b (1111).

    • Now, a=11a = 11.

  7. c=*ptr-a; Since ptr points to c, *ptr evaluates to the current value of c (2020).

    • c=20−11=9c = 20 - 11 = 9.

  8. printf("%d",c); Prints the value of c, which is 9.

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 Q60 of the GATE CSE 2026 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. 17 of them are 2-mark NAT questions like this one, and GATE CSE 2026 Set 2 has 3.

How GATE tests Programming in C

More from GATE CSE 2026 Set 2

Share this solution

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

GateAI solution cardGATE CSE 2026 Set 2 · Q60 · NAT

Consider the following ANSI-C program. #include int main(){ int *ptr, a, b, c; a=5; b=11; c=20; ptr=&a; *ptr=c; ptr=&c; a=*(&b); c=*ptr-a; printf("%d",c); return(0); } The output of this program is … (answer in integer) Note: Assume that the program compiles and runs successfully.

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.