C
Preprocessors
The preprocessor program is invoked by the compiler which modifies the source code before the actual composition takes place.
To use any preprocessor, we have to prefix them with a pound symbol (#).
The following are the preprocessor directives:
Category | Directives | Description |
Macro substitution division | #include | Include the File |
#define #undef | Macro define Macro undefine | |
#ifdef #ifndef | If Macro defined If Macro not defined | |
File inclusion division | #if #elif #else #endif | If Else if Else End if |
Compiler control division | #line #error #pragma | set the line number Aborting the compilation set compiler option |
Example 1:
#include<stdio.h> #define MAX 5 int main() { int i; for(i = 1; i <= MAX; i++) { printf("Hello %d", i); printf("\n"); } }
Output
Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
#undef MAX
#define MAX 10
#ifndef MAX #define MAX 100 #endif
The compiler will define MAX only when it is not defined before.