Explain different categories of Pre-Processor directives used in C.

Preprocessor Directives in C
Preprocessor directives are commands in C that are processed before the actual compilation starts.
They begin with a # (hash symbol) and are used to instruct the compiler to perform certain tasks like including files, defining constants, and controlling compilation.
These directives do not end with a semicolon.
Categories of Preprocessor Directives
Preprocessor directives are mainly divided into three categories:
• Macro Substitution
• File Inclusion
• Conditional Compilation
1. Macro Substitution (#define)
This is used to define constants or macros.
Instead of writing values again and again, we use macros.
#include <stdio.h>
#define PI 3.14
int main() {
float r = 5;
float area = PI r r;
printf("Area = %f", area);
return 0;
}
Explanation: PI is replaced by 3.14 before compilation.
2. File Inclusion (#include)
This is used to include header files in a program.
Header files contain predefined functions.
#include <stdio.h>
int main() {
printf("Hello World");
return 0;
}
Types:
• #include <file.h> → system file
• #include "file.h" → user-defined file
3. Conditional Compilation
This is used to compile specific parts of code based on conditions.
#include <stdio.h>
#define NUM 10
int main() {
#if NUM > 5
printf("Number is greater than 5");
#else
printf("Number is small");
#endif
return 0;
}
Explanation: Only the true condition block is compiled.
Other Important Directives
| Directive | Use |
|---|---|
| #undef | Undefine a macro |
| #ifdef | Check if macro is defined |
| #ifndef | Check if macro is not defined |
| #endif | End condition block |
Important Points for Exams
• Preprocessor runs before compilation
• No semicolon is used
• Macros improve readability
• Conditional compilation helps debugging
Final Tip
This is a theory question that appears frequently in exams. Focus on categories and examples to score full marks.

Written by
Palak PatelEducation writer Palak Patel covers the latest education news, board exam updates, results, and career opportunities.
Comments
No comments yet. Be the first!
