#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.

CategoryPreprocessor directives
KindKeyword / Statement
C standardC89 / 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 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.
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%

🙏 帮我们做得更好

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

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