Bird
0
0

What will be the output of this C code?

medium📝 Predict Output Q13 of 15
C - Loop Control Statements
What will be the output of this C code?
int main() {
    int x = 0;
    start:
    x++;
    if (x < 3) goto start;
    printf("%d", x);
    return 0;
}
A3
B0
C1
DInfinite loop
Step-by-Step Solution
Solution:
  1. Step 1: Trace the loop with goto

    The label start is before x++. The code increments x, then checks if x < 3. If yes, it jumps back to start.
  2. Step 2: Count increments until condition fails

    x starts at 0, increments to 1, 2, then 3. When x is 3, condition x < 3 is false, so it stops looping and prints 3.
  3. Final Answer:

    3 -> Option A
  4. Quick Check:

    Loop increments x to 3 before printing [OK]
Quick Trick: Count increments until condition fails [OK]
Common Mistakes:
  • Thinking it prints 0 or 1
  • Assuming infinite loop without checking condition
  • Confusing label position

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes