What are Preprocessor Directives ?

 
 

The preprocessor directives are instructions to the compiler. All these preprocessor lines begin with a pound (#). They are executed before the compilation of the code begins. These directives can only span a single line and does not need to end in a semicolon.
The preprocessor contains the following directives:
- #define: this defines an identifier and some value to this identifier. This value can be any character sequence and will be substituted in the code file for each instance of the corresponding identifier.
e.g. #define MIN 0
- #include: it tells the compiler to link to another source file. The name of the source file can be in angle brackets or double quotes.
e.g. #include
- #error: tells the compiler to stop compilation. Used primarily for debugging purposes.
- #if:
- #elif
- #endif
- #else: The above four directives are conditional directives. They allow you to conditionally include portions of code based on outcome of a constant expression.
E.g. #if OPTION == 1
//do something
#else
//do something else
#endif
- #ifndef
- #undef: the above indicates conditional compilation dependinf upon if a variable is defined or not defined.