In a switch control structure, what will happen if break is omitted in all the…
2025
In a switch control structure, what will happen if break is omitted in all the case blocks?
- A.
Only the matched case will execute, and control exits the switch block.
- B.
It will result in a compile-time error.
- C.
All cases after the matched case will execute sequentially until a break or end of switch.
- D.
The programme will crash due to undefined behaviour.
Attempted by 237 students.
Show answer & explanation
Correct answer: C
If the break statement is omitted in all the case blocks of a switch control structure, a behavior known as fall-through occurs.
Here is exactly what happens step-by-step:
Matching: The program evaluates the switch expression and jumps directly to the first
caselabel that matches the value.Execution: It executes the code inside that matching
case.Fall-Through: Because there is no
breakto stop it, the execution continues straight into the next case block, completely ignoring whether the subsequent case conditions match or not.Termination: The program will keep executing every single line of code in the subsequent cases until it finally hits the end of the entire
switchblock.