C #else

The #else preprocessor directive evaluates the expression or condition if condition of #if is false. It can be used with #if, #elif, #ifdef and #ifndef directives.

Syntax:

snippet
#if expression
//if code
#else
//else code
#endif

Syntax with #elif:

snippet
#if expression
//if code
#elif expression
//elif code
#else
//else code
#endif

C #else example

Let's see a simple example to use #else preprocessor directive.

snippet
#include 
#include 
#define NUMBER 1
void main() {
#if NUMBER==0
printf("Value of Number is: %d",NUMBER);
#else
print("Value of Number is non-zero");
#endif       
getch();
}

Output:

Output
Value of Number is non-zero
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents