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:
- Initially:
a = 5,b = 11,c = 20. ptr = &a; *ptr = c;setsa = 20.ptr = &c;makesptrpoint toc(so*ptris20).a = *(&b);setsa = b = 11.c = *ptr - a;computesc = 20 - 11 = 9.printf("%d", c);prints9.
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.