C Preprocessor Instructions – The Most Detailed

The C preprocessor is a macro processor that the compiler uses to make the necessary changes to the code before compilation begins.
C preprocessors are not part of the compiler; they are simply an additional step performed by the C compiler prior to compilation. As the name implies, it instructs the compiler to perform some pre-processing prior to compilation.
The preprocessor commands all start with the # symbol. The first line of the C program should always be the preprocessor directive.

Preprocessor directives in C

#include – Inserts the code with a specified header file. It copies the code from the specified header file and pastes it into the current C file.
#define – This command is used to define a constant or to replace a preprocessor macro.
#undef – A preprocessor macro that has not been defined. The #define directive has the opposite effect. It simply removes the constant or macro defined by the #define directive.
#ifdef – The #ifdef preprocessor directive determines whether or not a macro is defined by #define. If this macro is defined, it returns true.
#ifndef – This directive checks to see if the macro is defined by the #define directive. If yes, the code is executed; otherwise, the code defined in the #else directive is executed.
#if – This statement evaluates the expression or condition.
If the #if directive condition returns false, it evaluates the expression or condition.
#elif – A combination of the directives #if and #else.
#endif – Terminates the preprocessor condition specified.
#error – Displays an error message. If the #error directive is found, the compiler generates a fatal error and skips the rest of the compilation process.
#pragma – This is used to send special commands or information to the compiler.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button