Preprocessor directives

Home / C Programming / Preprocessor directives

Preprocessor directives


In C programming, preprocessor directives are special instructions that are processed by the preprocessor before the actual compilation of the code. They begin with a hash symbol (#) and are typically used to include header files, define constants, perform conditional compilation, and enable or disable certain features.

Here are some commonly used preprocessor directives in C:

#include: This directive is used to include header files in the code. It allows you to use functions and definitions from the included files.

#define: This directive is used to define constants or macros. It allows you to create symbolic names for values or code snippets.


#ifdef, #ifndef, #endif: These directives are used for conditional compilation. They allow you to include or exclude sections of code based on certain conditions.

#if, #elif, #else: These directives are used for conditional compilation based on constant expressions.

#undef: This directive is used to undefine a previously defined macro. It removes the definition of a macro or constant.

#pragma: This directive provides implementation-specific instructions to the compiler. It allows you to control various compiler settings and behaviors. The behavior of #pragma directives is compiler-dependent.