Bird
0
0

What is the output of this code?

medium📝 Predict Output Q13 of 15
C - Loops
What is the output of this code?
for(int i = 1; i <= 3; i++) {
    printf("%d ", i);
}
A3 2 1
B0 1 2 3
C1 2 3
D1 2 3 4
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the loop range

    The loop starts at i=1 and runs while i is less than or equal to 3, incrementing i by 1 each time.
  2. Step 2: Determine printed values

    It prints i each time: 1, then 2, then 3, then stops.
  3. Final Answer:

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

    Loop prints 1 to 3 [OK]
Quick Trick: Check loop start, end, and increments carefully [OK]
Common Mistakes:
  • Starting loop at 0 instead of 1
  • Including an extra number beyond 3
  • Printing in reverse order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes