Bird
0
0

What will be the output of this code snippet?

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

What will be the output of this code snippet?

int i = 0;
while(i < 4) {
    if(i == 2) break;
    printf("%d ", i);
    i++;
}
A0 1
B0 1 2
C0 1 2 3
D1 2
Step-by-Step Solution
Solution:
  1. Step 1: Follow loop execution

    Loop starts with i=0, prints 0 and increments i. At i=2, break stops the loop before printing.
  2. Step 2: Identify printed values

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

    0 1 -> Option A
  4. Quick Check:

    Break stops loop before printing 2 [OK]
Quick Trick: Break stops loop before printing current value [OK]
Common Mistakes:
  • Assuming break prints the current value
  • Forgetting to increment before break
  • Confusing while loop behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes