GATE CS 2026 Set 2 | Question 19
Programming & Data Structures › Basics & Control Structures · MCQ · 1 mark · Answer: A
- Question 19Programming & Data Structuresmcq1 markConsider the following three ANSI-C programs, P1, P2, and P3.
Which one of the following statements is true?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); }- 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 localint asimply shadows the globala— legal. In P2 and P3 the identifierais redeclared in the same scope (asint/intandint/float), which is a compile-time error. Hence only P1 compiles. - A.
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 →