C Preprocessor


C Preprocessor is not a part of the compiler in the C program, but it is a separate function in the compilation process. Also, we can say it’s a text substitution tool and it instructs the compiler to do the required preprocessing before the actual compilation process. C Pre-processor refers as CPP in the program.

All the pre-processors commands begin with a hash symbol (#). It must be the first non-blank character and for readability. It directive should begin in the first column.


These are the important preprocessor directives −

These are basic file operations to perform.

  • #define: It substitutes a pre-processor macro.
  • #include: It inserts a particular header from another file.
  • #undef: It undefines a preprocessor macro.
  • #ifdef: It returns a true if this macro is defined.
  • #ifndef: It returns a true if this macro is not defined.
  • #if: It tests if a compile time condition is true.
  • #else: It’s alternative for #if directive.
  • #elif: #else and #if should be in one statement.
  • #endif: It ends a preprocessor conditional.
  • #error: It prints an error message on stderr.
  • #pragma: It issues the special command to the compiler, using the standardized method.

Example:

#define MAX_ARRAY_LENGTH 5

 

In this example the CPP is to replace the instances of MAX_ARRAY_LENGTH with 5




OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.