Skip to content
Official PYQ · 2026

GATE CS 2026 Set 1 Q24 — Programming in C

Explain with AI

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.

View worked solution

Answer: 09 :09

To find the output of the program, let's trace the execution step-by-step:

  1. The main() function calls func(9, 10), passing i = 9 and j = 10.
  2. Inside func(int i, int j), the condition if (i < j) (i.e., 9 < 10) is true.
  3. Inside the if block, a new local variable int i = 0; is declared. This variable shadows the parameter i within the scope of the if block.
  4. The while (i < 10) loop increments this inner i up to 10.
  5. Once the if block terminates, the inner i goes out of scope and is destroyed.
  6. The printf("%d", i); statement is outside the if block, so it refers to the parameter i, which remains unchanged with its original value of 9.

Thus, the program prints 9.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Programming in C questions