Bird
0
0

What will be the output of this C code?

medium📝 Predict Output Q4 of 15
C - Loops
What will be the output of this C code?
int i = 1;
do {
    printf("%d ", i);
    i++;
} while (i <= 3);
A2 3 4
B1 2 3 4
CNo output
D1 2 3
Step-by-Step Solution
Solution:
  1. Step 1: Trace the loop iterations

    Start with i=1, print i, then increment i. Loop continues while i <= 3.
  2. Step 2: List printed values

    Values printed are 1, 2, and 3. When i becomes 4, condition fails and loop stops.
  3. Final Answer:

    1 2 3 -> Option D
  4. Quick Check:

    Loop prints 1 to 3 inclusive [OK]
Quick Trick: do-while runs body before condition check [OK]
Common Mistakes:
  • Including 4 in output mistakenly
  • Starting print from 2 instead of 1
  • Assuming no output if condition false initially

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes