#else Provide a fallback preprocessing branch

#else Provide a fallback preprocessing branch

#else is the fallback when no earlier branch is selected. A group allows one #else, after any #elif and before #endif, and it takes no condition.

CategoryPreprocessor directives
KindKeyword / Statement
C standardC89 / C90

📝 Syntax

#if constant-expression
    /* first branch */
#else
    /* fallback branch */
#endif

▶ Example

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

Output:

Disabled
ℹ️ Info A conditional group can have at most one #else. It takes no condition and belongs after every #elif and before the matching #endif.

📚 Related Tutorials

❓ FAQ

QIs #else if valid for preprocessor conditionals?
AUse #elif for another preprocessing condition, not #else if. If a new #if is deliberately nested after #else, that inner group needs its own #endif.
QCan #else be used with #ifdef or #ifndef?
AYes. #else can belong to a group started by #if, #ifdef, or #ifndef and supplies the alternative lines when the earlier branch is not selected.
QWhich #if does #else match in conditional preprocessing?
AIt matches the nearest unclosed conditional group at the same nesting level, not simply the closest #if in the file. An intervening #if must first be closed by its own #endif before the outer #else can be associated correctly. Indentation and pairing comments help prevent mistakes.
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%

🙏 帮我们做得更好

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

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