Bird
0
0

What will be the output of the following C code?

medium📝 Predict Output Q13 of 15
C - Loops
What will be the output of the following C code?
int i = 3;
do {
    printf("%d ", i);
    i--;
} while (i > 0);
A1 2 3
B2 1 0
C3 2 1 0
D3 2 1
Step-by-Step Solution
Solution:
  1. Step 1: Trace the loop iterations

    Initially, i = 3. The loop prints i, then decrements i by 1. It repeats while i > 0.
  2. Step 2: List printed values

    First iteration: prints 3, i becomes 2
    Second iteration: prints 2, i becomes 1
    Third iteration: prints 1, i becomes 0
    Loop stops because i is not > 0.
  3. Final Answer:

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

    Prints 3 down to 1 = A [OK]
Quick Trick: Count printed values before condition fails [OK]
Common Mistakes:
  • Including 0 in output
  • Starting from 2 instead of 3
  • Printing in ascending order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes