C - Preprocessor Directives
C - Preprocessor Directives
- In C Language preprocessor is more or less the own language which can be a very powerful tool to the programmer .
- All the preprocessor directives or commands begin with “#” .
- Below is the list of preprocessor directives that C language offers .
Preprocessors | Syntax | Description |
---|---|---|
Macro | #define | This macro defines constant value and can be any of the basic data types. |
Header file inclusion | #include <file_name> | The source code of the file “file_name” is included in the main program at the specified place |
Conditional compilation | #ifdef, #endif, #if, #else, #ifndef | Set of commands are included or excluded in source program before compilation with respect to the condition |
Other directives | #undef, #pragma | #undef is used to undefine a defined macro variable. #Pragma is used to call a function before and after main function in a C program |
- It must be the first nonblank character, and for readability, a preprocessor directive should begin in the first column.
- The following section lists down all the important preprocessor directives :
Directive | Description |
---|---|
#define | Substitutes a preprocessor macro. |
#include | Inserts a particular header from another file. |
#undef | Undefines a preprocessor macro.. |
#ifdef | Returns true if this macro is defined.. |
#ifndef | Returns true if this macro is not defined. |
#if | Tests if a compile time condition is true.. |
#else | The alternative for #if. |
#elif | #else and #if in one statement.. |
#endif | Ends preprocessor conditional. |
#error | Prints error message on stderr. |
#pragma | Issues special commands to the compiler, using a standardized method.. |
- Use of the preprocessor in C programming :
- Programs easier to develop,
- Easier to read,
- Easier to modify