Multiple choice technology programming languages

What does the line containing "break;" do in the following code? void afunction() { if(1) { break; a_function(); cout<<"Err"; } }

  1. Breaks out of the if statement

  2. Exits the function

  3. Nothing (Compiler error)

  4. None of the Above

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 contained in a loop or switch is a compilation error. The code attempts to break from just an if block, which is invalid.