Bird
0
0

What is the output of this code?

medium📝 Predict Output Q4 of 15
C - Loops
What is the output of this code?
int i = 0;
while (i < 3) {
    printf("%d", i);
    i++;
}
A0123
B123
C012
D321
Step-by-Step Solution
Solution:
  1. Step 1: Trace the loop iterations

    i starts at 0, loop runs while i < 3, printing i each time, then increments i.
  2. Step 2: List printed values

    Values printed are 0, then 1, then 2. Loop stops when i becomes 3.
  3. Final Answer:

    012 -> Option C
  4. Quick Check:

    Loop prints 0 to 2 = 012 [OK]
Quick Trick: Loop runs while condition true, prints i before increment [OK]
Common Mistakes:
  • Including 3 in output
  • Printing after loop ends
  • Off-by-one errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes