Consider the following program in C: #include void func(int i, int j) { if(i The output of the program is … (answer in integer) Note: Assume that the program compiles and runs successfully.
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2026 Set 1 · Q34
Time
#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;
}The output of the program is ________. (answer in integer)
Note: Assume that the program compiles and runs successfully.Your answerNumerical answer
Solution
Official answer: 9
Programming in CLet us trace the execution of the program step-by-step:
In main(), local variables i = 9 and j = 10 are initialized, and func(9, 10) is called by value.
In func(int i, int j), the formal parameters are initialized as and .
The condition if (i < j) evaluates to 9 < 10, which is true.
Inside the if block, a new block-scoped variable int i = 0; is declared. This variable shadows the outer parameter i throughout the inner block.
The while loop iterates and increments the block-scoped i until it reaches 10.
After the if block terminates, the inner i goes out of scope.
The statement printf("%d", i); accesses the outer parameter i, whose value remains unchanged at 9.
Therefore, the program outputs 9.
Try the question first, then check your work.
Examiner trap
Pay attention to block scope and variable shadowing inside the if block.
This Programming in C previous year question is Q34 of the GATE CSE 2026 Set 1 paper. Find more GATE CSE PYQs on Programming in C in Programming and Data Structures, or browse all GATE CSE PYQs.
Free diagnostic
Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Programming in C PYQs now with no account.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
Programming in C has 74 GATE CSE PYQs across 25 papers from 2011 to 2026. 16 of them are 1-mark NAT questions like this one, and GATE CSE 2026 Set 1 has 2.
How GATE tests Programming in CIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.