GATE 2026 CS (CS2) – Question 60
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.
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: 9
Explanation
Initially $a=5$, $b=11$, and $c=20$. The statement `ptr=&a; *ptr=c;` stores 20 into $a$, so now $a=20$. Then `ptr=&c;` makes `ptr` point to $c$. Next, `a=*(&b);` assigns the value of $b$ to $a$, so $a=11$. Finally, `c=*ptr-a` means $c=c-a=20-11=9$. Therefore, the program prints 9.