Question

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.

Official answer and solution
Official answer
9
From
Official GATE 2026 answer key

Solution

Trace the values of a, b, c, and *ptr statement by statement.

Tracing the execution step by step:

  1. Initially: a = 5, b = 11, c = 20.
  2. ptr = &a; *ptr = c; sets a = 20.
  3. ptr = &c; makes ptr point to c (so *ptr is 20).
  4. a = *(&b); sets a = b = 11.
  5. c = *ptr - a; computes c = 20 - 11 = 9.
  6. printf("%d", c); prints 9.
Final answer

9

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2026 Computer Science and Information Technology - Session 2 (CS2)
Question
60 of 65
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.