![]() |
VOOZH | about |
The C preprocessor is a program that processes the source code before actual compilation begins. It handles special instructions called preprocessor directives, which guide the compiler on how to prepare the code.
The #define directive is used to define macros or symbolic constants. These values are replaced before compilation.
201.061760
The #include directive is used to include header files in a program before compilation.
Syntax
#include <filename>
#include "filename"
< > -> system header files " " -> user-defined header files Hello, Geek!
These directives work together to control which parts of the program get compiled based on certain conditions.
Value is less than or equal to 2
Note: the entire structure of #if, #elif and #else chained directives ends with #endif.
The #ifdef (if defined) directive checks whether a macro is defined. If it is, the code within the #ifdef block is included in the program.
Debugging is enabled
The #ifndef (if not defined) directive checks if a macro is not defined. If it is not defined, the code inside the #ifndef block is included.
Debugging is not enabled
The #line directive is used to change line number and file name for the compiler.
Line number is 5 in file named ./Solution.c Line number is 20 in file named main.c Line number is 30 in file named index.c
Line number that will be assigned to the next code line. The line numbers of successive lines will be increased one by one from this point on. "filename" - optional parameter that allows to redefine the file name that will be shown.
The #error directive generates a compilation error with a custom message.
Output
error: #error "GeeksforGeeks not found!"The #pragma directive gives special instructions to the compiler.
Commonly used pragma directives are:
Output
#pragma message: GfG is not defined.| Preprocessor Directives | Description |
|---|---|
#define | Used to define a macro. |
#undef | Used to undefine a macro. |
#include | Used to include a file in the source code program. |
#ifdef | Used to include a section of code if a certain macro is defined by #define. |
#ifndef | Used to include a section of code if a certain macro is not defined by #define. |
#if | Check for the specified condition. |
#else | Alternate code that executes when #if fails. |
#endif | Used to mark the end of #if, #ifdef, and #ifndef. |
#error | Used to generate a compilation error message. |
#line | Used to modify line number and filename information. |
#pragma once | To make sure the header is included only once. |
#pragma message | Used for displaying a message during compilation. |