C Preprocessor Directives

Before a C program is compiled in a compiler, source code is processed by a program called preprocessor. The C preprocessor is a microprocessor invoked by the compiler that modifies the source code before the actual composition takes place. The C Preprocessor is not a part of the compiler, but is a separate step in the compilation process. In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do required pre-processing before the actual compilation.

Commands used in preprocessor are called preprocessor directives and they begin with “#” symbol. Some of the preprocessor directives are listed below :

Preprocessor Directive Description
#define Substitutes a preprocessor macro.
#include Inserts a particular header from another file.
#undef Undefines a preprocessor macro.
#ifdef Returns true if this macro is defined.
#ifndef Returns true if this macro is not defined.
#if Tests if a compile time condition is true.
#else The alternative for #if.
#elif #else and #if in one statement.
#endif Ends preprocessor conditional.
#error Prints error message on stderr.
#pragma Issues special commands to the compiler, using a standardized method.


Next Topic :