Bird
0
0

What will be the output of this C code?

medium📝 Predict Output Q4 of 15
C - Loop Control Statements
What will be the output of this C code?
int i = 0;
while(i < 3) {
  printf("%d ", i);
  i++;
  if(i == 2) break;
}
A0 1 2
B0 1
C1 2
D0 1 2 3
Step-by-Step Solution
Solution:
  1. Step 1: Trace loop iterations and print statements

    i starts at 0, prints 0, increments to 1, prints 1, increments to 2.
  2. Step 2: Check break condition

    When i becomes 2, break stops the loop immediately, so 2 is not printed.
  3. Final Answer:

    0 1 -> Option B
  4. Quick Check:

    Break stops loop before printing 2 [OK]
Quick Trick: Break stops loop before next print [OK]
Common Mistakes:
  • Assuming break prints current value
  • Ignoring break condition
  • Confusing increment order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes