Bird
0
0

What will be the output of the following C code?

medium📝 Predict Output Q13 of 15
C - Loop Control Statements

What will be the output of the following C code?

int i;
for(i = 0; i < 5; i++) {
    if(i == 2) {
        break;
    }
    printf("%d ", i);
}
A0 1
B0 1 2
C2
D0 1 2 3 4
Step-by-Step Solution
Solution:
  1. Step 1: Trace loop iterations until break

    The loop starts i=0, prints 0; i=1, prints 1; when i=2, break triggers and loop stops.
  2. Step 2: Determine printed values

    Only 0 and 1 are printed before break stops the loop.
  3. Final Answer:

    0 1 -> Option A
  4. Quick Check:

    Break at i=2 stops loop, prints 0 1 [OK]
Quick Trick: Break stops loop before printing i=2 [OK]
Common Mistakes:
  • Including value at break condition in output
  • Confusing break with continue
  • Assuming loop runs fully

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes