default Default switch branch
default Default switch branch
default labels one optional switch branch for unmatched values; it can sit anywhere and fall through. Without a match or default, the switch is skipped.
| Category | Control flow |
|---|---|
| Kind | Keyword / Statement |
| C standard | C89 / C90 |
📝 Syntax
default: statement;
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
other
🏷️ Related control-flow keywords
📚 Related Tutorials
❓ FAQ
QMust a switch provide a default branch?
AIt is not syntactically required and can be omitted when all possible values are handled. Keeping default is often useful for defending against invalid values; the choice depends on whether unmatched cases should be ignored silently.
QMust default appear last in a switch?
ANo. It can appear anywhere a label is permitted in the switch body. If default is in the middle, execution can still fall through to later cases, so the usual branch-termination rules apply.
QWhat happens when no case matches and there is no default?
AControl skips the entire switch body without executing any labeled branch, then continues with the statement following the switch.