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.

CategoryControl flow
KindKeyword / Statement
C standardC89 / C90

📝 Syntax

default: statement;

▶ Example

Edit the C code below and click Run; the server compiles and executes it:

Output:

other

📚 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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏