#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:
#if expression//if code #else//else code #endif
Syntax with #elif:
#if expression//if code #elif expression//elif code #else//else code #endif
#else example
see a simple example to use #else preprocessor directive.#include <stdio.h> #define NUMBER 5 void main() { #if NUMBER==0 printf("Value of Number is equal: %d",NUMBER); #else printf("Value of Number is not equal"); #endif } Output: Value of Number is not equal
#error
The #error preprocessor directive indicates error. The compiler gives fatal error if #error directive is found and skips further compilation process. #error example: see a simple example to use #error preprocessor directive.
#include <stdio.h> #ifndef __MATH_H #error First execute then compile it #else void main(){ float c; c=sqrt(7); printf("%f",c); } #endif Output: compile Time Error: First execute then compile it
#include <stdio.h> #include <math.h> #ifdef __MATH_H #error First execute then compile it #else void main(){ float c; c=sqrt(7); printf("%f",c); } #endif Output: 2.645751
#pragma
The #pragma preprocessor directive is used to provide additional information to the compiler. The #pragma directive is used by the compiler to offer machine or operating-system feature. Syntax:
#pragma token
Different compilers can provide different usage of #pragma directive.