`case` — C++ Keyword
`case` — C++ Keyword
The case keyword in C++: defines a labeled branch inside a switch statement.
`case` — C++ Keyword
The case keyword in C++: defines a labeled branch inside a switch statement.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
caseDefines a labeled branch inside a switch statement. Execution jumps to the matching case label when the switch expression equals its constant.
switch (expression) {
case constant-expression: statements
case constant-expression: statements
default: statements
}
#include <print>
int main() {
char c = 'e';
switch (c) {
case 'a': case 'e': case 'i':
case 'o': case 'u':
std::println("vowel"); // executed
break;
default:
std::println("consonant");
}
}
case label must be an integer constant expression unique within the switch.case labels with no intervening break share one body (fall-through grouping).switchint main() {
// Pick one facility from this reference page.
// Write the smallest program that exercises its main precondition,
// complexity rule, or lifetime constraint before scaling up.
return 0;
}