The C preprocessor processes specific instructions before the actual compilation of code begins. These instructions, called preprocessor directives, begin with the # symbol and are not C statements themselves. They help in defining constants, including files, controlling conditional compilation, and more. Preprocessor directives are powerful tools that enhance modularity, portability, and maintainability of C programs.
1. #define – Define Macros:
Used to create symbolic constants or macros that are replaced before compilation. Helps reduce repetition and makes code easier to maintain.
2. #include – Include Files:
Inserts the content of a file (like header files) into the program. Essential for using built-in or custom libraries.
3. #undef – Undefine a Macro:
Removes a previously defined macro, allowing redefinition or preventing its further use.
4. #ifdef – If Defined:
Includes code only if a specific macro is already defined, useful for conditional compilation.
5. #ifndef – If Not Defined:
Includes code only if a macro is not defined, preventing duplicate definitions.
6. #else and #endif – Alternate and End Blocks:
Provides alternate code when #ifdef/#ifndef conditions fail and ends conditional compilation blocks.