`default` — C++ Keyword
`default` — C++ Keyword
The default keyword in C++: fallback branch in a switch statement, and default arguments/definitions.
`default` — C++ Keyword
The default keyword in C++: fallback branch in a switch statement, and default arguments/definitions.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
defaultIn a switch statement, default marks the fallback branch executed when no case label matches. It also appears in function declarations (= default) to request a compiler-generated special member.
// switch fallback
switch (expr) {
case N: ...
default: statements
}
// compiler-generated special member
ClassName() = default;
#include <print>
int main() {
int code = 99;
switch (code) {
case 0: std::println("OK"); break;
case 1: std::println("Error"); break;
default: std::println("Unknown"); break; // executed
}
}
struct Point {
int x, y;
Point() = default; // compiler generates the default constructor
};
default label per switch.= default on a special member function requests the compiler-generated version and marks it as noexcept when possible.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;
}