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?
for(int i = 2; i <= 6; i += 2) {
    printf("%d ", i);
}
A2 4 6
B2 3 4 5 6
C2 4 6 8
D0 2 4 6
Step-by-Step Solution
Solution:
  1. Step 1: Analyze loop initialization and condition

    Loop starts at i=2, runs while i ≤ 6, incrementing i by 2 each time.
  2. Step 2: List values of i during iterations

    Values: 2, 4, 6. After 6, next i=8 which breaks condition.
  3. Final Answer:

    2 4 6 -> Option A
  4. Quick Check:

    Loop prints even numbers 2 to 6 [OK]
Quick Trick: Increment by 2 prints even numbers [OK]
Common Mistakes:
  • Assuming it prints all numbers 2 to 6
  • Including 8 in output
  • Starting from 0 instead of 2

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes