Bird
0
0

Consider this code snippet:

hard📝 Application Q9 of 15
C - Loop Control Statements
Consider this code snippet:
int main() {
    int i = 0;
    loop:
    if (i == 5) goto end;
    printf("%d ", i);
    i++;
    goto loop;
    end:
    return 0;
}

What is the output and why?
A0 1 2 3 4 5 , because i==5 is printed
B0 1 2 3 4 , because loop stops at i==5
CInfinite loop, because goto loops endlessly
DCompilation error due to label placement
Step-by-Step Solution
Solution:
  1. Step 1: Trace the loop and condition

    Loop prints i from 0 to 4. When i==5, goto jumps to end, stopping loop.
  2. Step 2: Confirm output

    Numbers 0 1 2 3 4 printed with spaces, no 5 printed.
  3. Final Answer:

    0 1 2 3 4 , because loop stops at i==5 -> Option B
  4. Quick Check:

    Goto breaks loop at condition [OK]
Quick Trick: Goto can break loops early with condition [OK]
Common Mistakes:
  • Expecting 5 to print
  • Thinking loop is infinite
  • Assuming label causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes