GateAI
Programming in C

GATE CSE 2026 Set 1 · Q34

NAT1 markEasy

Time

Consider the following program in C:#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

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 9

Programming in C

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

  1. In main(), local variables i = 9 and j = 10 are initialized, and func(9, 10) is called by value.

  2. In func(int i, int j), the formal parameters are initialized as i=9i = 9 and j=10j = 10.

  3. The condition if (i < j) evaluates to 9 < 10, which is true.

  4. 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.

  5. The while loop iterates and increments the block-scoped i until it reaches 10.

  6. After the if block terminates, the inner i goes out of scope.

  7. 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.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

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

Where do you stand for GATE?

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.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Programming in C in GATE CSE

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 C

More from GATE CSE 2026 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2026 Set 1 · Q34 · NAT

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

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.