GATE CS 2026 Set 1 | Question 34

Programming & Data Structures › Advanced Concepts · NAT · 1 mark · Answer: 9

  1. Question 34Programming & Data Structuresnat1 mark
    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.

    Answer: 9

    Solution

    Answer: 9 Inside the if block, int i = 0; declares a new i that shadows the parameter. The loop changes only that inner i (and j). The inner i goes out of scope when the block ends, so printf sees the parameter i = 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 →