Bird
0
0

What is the output of this C code?

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

    Start i=1; print 1; i becomes 3; print 3; i becomes 5; loop ends as 5 > 3.
  2. Step 2: Collect printed values

    Printed values are "1 " and "3 ".
  3. Final Answer:

    1 3 -> Option C
  4. Quick Check:

    Loop increments by 2, prints 1 and 3 [OK]
Quick Trick: Increment affects which values print in loop [OK]
Common Mistakes:
  • Assuming increments by 1
  • Printing after loop ends
  • Confusing loop condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes