GATE CS 2026 Set 2 | Question 19

Programming & Data Structures › Basics & Control Structures · MCQ · 1 mark · Answer: A

  1. Question 19Programming & Data Structuresmcq1 mark
    Consider the following three ANSI-C programs, P1, P2, and P3.
    c
    // P1 #include <stdio.h> int a=5; int main(){ int a=7; return(0); } // P2 #include <stdio.h> int main(){ int a=5; int a=7; return(0); } // P3 #include <stdio.h> int main(){ int a=5; float a=7; return(0); }
    Which one of the following statements is true?
    • A.
      Only P1 will compile without any error
      ✓
    • B.
      Only P2 will compile without any error
    • C.
      Only P3 will compile without any error
    • D.
      All three programs P1, P2, and P3 will compile without any error

    Answer: A

    Solution

    Answer: (A) In P1 the local int a simply shadows the global a — legal. In P2 and P3 the identifier a is redeclared in the same scope (as int/int and int/float), which is a compile-time error. Hence only P1 compiles.

More GATE PYQ on Basics & Control Structures

All GATE CS Programming & Data Structures PYQ →

Attempt GATE CS 2026 Set 2 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →