GATE CS 2026 Set 1 | Question 34
Programming & Data Structures › Advanced Concepts · NAT · 1 mark · Answer: 9
- Question 34Programming & Data Structuresnat1 markConsider the following program in C:
The output of the program is _________. (answer in integer) Note: Assume that the program compiles and runs successfully.#include <stdio.h> void func(int i, int j) { if(i < j) { int i = 0; while (i < 10) { j += 2; i++; } } printf("%d", i); } int main() { int i = 9, j = 10; func(i, j); return 0; }Answer: 9
Solution
Answer: 9 Inside theifblock,int i = 0;declares a newithat shadows the parameter. The loop changes only that inneri(andj). The innerigoes out of scope when the block ends, soprintfsees the parameteri = 9.
More GATE PYQ on Advanced Concepts
All GATE CS Programming & Data Structures PYQ →Attempt GATE CS 2026 Set 1 in real GATE exam mode
Full paper with a timer, the GATE interface and a topic-wise analysis — free.
Create free account →