Multiple choice

What does the line containing "break;" do in the following code?

void afunction() { if(1) { break; afunction(); printf("Error"); } }

  1. Breaks out of the if statement

  2. Exits the function

  3. Compiler error

  4. Nothing

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The break statement can only be used inside loops (for, while, do-while) or switch statements. Using break inside an if statement that is not inside a loop or switch causes a compilation error. The compiler will reject this code because break has no valid target to break out of.