A case statement is C’s multiple-selection construct. It evaluates the switch expression, transfers control to the matching case label, or selects default when no case matches. Case and default labels act as jump targets inside the secondary block. section 3.0 section 3.3
Selecting among character values
switch (arg) { case 'm': puts("this is a magpie"); break; case 'r': puts("this is a raven"); break; case 'j': puts("this is a jay"); break; case 'c': puts("this is a chough"); break; default: puts("this is an unknown corvid"); } Each break terminates the enclosing switch and transfers control to the following statement. Without break, execution continues into subsequent cases. section 3.3
Use case labels within these constraints:
- Make every case value an integer constant expression; variables belong in the switch expression, not as case values. section 3.3
- Keep case values unique within one switch statement. section 3.3
- Treat fall-through deliberately: execution continues until break or the end of the secondary block. section 3.3 section 3.4
- Guard declarations carefully inside the block, because a jump directly to a case can leave a variable uninitialized. section 3.3
switch (count) {
default:puts("++++ ..... +++");
case 4: puts("++++");
case 3: puts("+++");
case 2: puts("++");
case 1: puts("+");
case 0: // prior to C23 this needed an extra ``;"
}
Shows intentional fall-through by selecting a count and then running the matching and subsequent case bodies. section 3.3








