What is the purpose of [[fallthrough]]; at the end of a case in C23?
The attribute documents intent. With -Wimplicit-fallthrough the compiler can then warn about every unmarked fall-through, which is almost always a forgotten break.
Control Instructions · Exercise 1 of 4
Twelve multiple-choice questions on if-else, switch, fall-through, short-circuit evaluation, the conditional operator, goto and the C23 changes. Pick an option to check your answer instantly.
What is the purpose of [[fallthrough]]; at the end of a case in C23?
The attribute documents intent. With -Wimplicit-fallthrough the compiler can then warn about every unmarked fall-through, which is almost always a forgotten break.
Is a declaration directly after a case label, as in case 1: int x = 5;, valid?
Until C17, a label had to label a statement, and a declaration is not one. The usual workaround was braces: case 1: { int x = 5; … }. C23 now allows the declaration directly.
Timed online tests with instant scores and explanations.