Skip to content
Official PYQ · 2026

GATE CS 2026 Set 2 Q50 — Programming in C

Explain with AI

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.

View worked solution

Answer: 9:9

Let us trace the execution of the program step-by-step:

  1. Variable Initialization:
    a = 5, b = 11, c = 20
  2. Pointer Assignment and Dereferencing:
    • ptr = &a;: The pointer ptr points to the variable a.
    • *ptr = c;: The value at the address pointed to by ptr (which is a) is updated to the value of c.
      Thus, a = 20.
    • ptr = &c;: The pointer ptr is updated to point to the variable c.
  3. Value Updates:
    • a = *(&b);: The expression *(&b) evaluates to the value of b.
      Thus, a is updated to 11.
    • c = *ptr - a;: Since ptr points to c, *ptr evaluates to the current value of c (which is 20).
      Thus, c = 20 - 11 = 9.
  4. Output:
    • printf("%d", c); prints the final value of c, which is 9.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Programming in C questions