In switch control structure, what will happen if break is

2025

In a switch control structure, what will happen if break is omitted in all the case blocks?

  1. A.

    Only the matched case will execute, and control exits the switch block.

  2. B.

    It will result in a compile-time error.

  3. C.

    All cases after the matched case will execute sequentially until a break or end of switch.

  4. D.

    The programme will crash due to undefined behaviour.

Attempted by 234 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:

  1. Matching: The program evaluates the switch expression and jumps directly to the first case label that matches the value.

  2. Execution: It executes the code inside that matching case.

  3. Fall-Through: Because there is no break to stop it, the execution continues straight into the next case block, completely ignoring whether the subsequent case conditions match or not.

  4. Termination: The program will keep executing every single line of code in the subsequent cases until it finally hits the end of the entire switch block.

Explore the full course: Dsssb Tgt Computer Science Paper 2