#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.
| Category | Preprocessor directives |
|---|---|
| Kind | Keyword / Statement |
| C standard | C89 / 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 preprocessor directives
📚 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.