C Preprocessor Directives

The C preprocessor is a micro processor that is used by compiler to transform your code before compilation. It is called micro preprocessor because it allows us to add macros.All preprocessor directives starts with hash # symbol.

Some advantages of using preprocessor are-

  • Readability of the program is increased.
  • Makes the program portable and efficient.
  • Program modification becomes easy.

We know that the code that we write is translated into object code by the compiler. But before being compiled, the code is passed through the C preprocessor. The preprocessor scans the whole source code and modifies it, which is then given to the compiler.

The lines starting with the symbol # are known as preprocessor directives. When the preprocessor finds a line starting with the symbol #, it considers it as a command for itself and works accordingly. All the directives are executed by the preprocessor, and the compiler does not receive any line starting with # symbol.

List of Preprocessor Directives:-

To execute a preprocessor program on a certain statement, some of the preprocessor directives types are:

#define : It substitutes a preprocessor using macro.

#include : It helps to insert a certain header from another file.

#undef : It undefines a certain preprocessor macro.

#ifdef : It returns true if a certain macro is defined.

#line : It handles the line numbers on the errors and warnings. It can be used to change the line number and source files while generating output during compile time.

#error and #warning : It can be used for generating errors and warnings.

Leave a Comment

Your email address will not be published.