In the C Programming Language, the #endif
directive is used to define the following directives: #if, #ifdef
, and #ifndef
. Whenever the #endif
directive is encountered in a program, it determines if the preprocessing of #if, #ifdef, or #ifndef has been completed successfully.
#endif
#if (expression)
// given that expression is true, if is executed.
//code
#endif
#if expression
//if code
// instead of else if, we use elif in this directive.
#elif expression
//elif code
#else
//else code
#endif
Let’s look at a simple coding example:
#include <stdio.h>#define NUMBER -2int main() {#if (NUMBER>0)printf("Value of Number greater than 0 is: %d",NUMBER);#elseprintf("Value of Number less than 0 is: %d",NUMBER);// #endif is used to determine the end the if condition.#endifreturn 0;}
Free Resources