#endif End a conditional preprocessing group
#endif End a conditional preprocessing group
#endif closes the nearest open #if, #ifdef, or #ifndef group. It takes no condition or semicolon; nested groups require their own matching directives.
| Category | Preprocessor directives |
|---|---|
| Kind | Keyword / Statement |
| C standard | C89 / C90 |
📝 Syntax
#if constant-expression
/* conditional code */
#else
/* alternative code */
#endif
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
Level two
ℹ️ Info #endif takes no condition and no trailing semicolon. In a long group, #endif /* LEVEL */ can document which group it closes.
🏷️ Related preprocessor directives
📚 Related Tutorials
❓ FAQ
QDoes #endif need to repeat the condition?
ANo. The preprocessor pairs #endif with the nearest open conditional group. A descriptive comment may be added for readability.
QAre #endif and a closing brace equivalent?
ANo. #endif closes a preprocessing conditional group, whereas } closes a C compound statement or definition. They belong to different phases and cannot replace each other.
QHow do I troubleshoot an unterminated #if or a mismatched #endif?
AStarting at the diagnostic, match each #if, #ifdef, or #ifndef with its #endif, and check nested groups and included headers for cross-file mismatches. Comments can mark levels but cannot replace directives. Conditional directive pairs must remain balanced even in skipped groups.