Bird
0
0

Identify the error in this loop code:

medium📝 Debug Q14 of 15
C - Loops
Identify the error in this loop code:
int i = 0;
while (i < 5) {
    printf("%d ", i);
}
AIncorrect printf format specifier
BMissing increment of i inside the loop
CCondition should be i <= 5
DVariable i should be declared inside the loop
Step-by-Step Solution
Solution:
  1. Step 1: Check loop body for changes to i

    The variable i is never incremented inside the loop, so i stays 0 forever.
  2. Step 2: Understand loop consequence

    Without increment, the condition i < 5 is always true, causing an infinite loop.
  3. Final Answer:

    Missing increment of i inside the loop -> Option B
  4. Quick Check:

    Infinite loop due to no i++ [OK]
Quick Trick: Always update loop variable to avoid infinite loops [OK]
Common Mistakes:
  • Thinking condition is wrong instead of missing increment
  • Assuming printf format is incorrect
  • Declaring i inside loop is optional, not error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes