< C++ Tutorial

C++ preprocessor

← Previous Next →


Before Compiler compile the source code, a program called preprocessor prcoess the source code.

About Preprocessor:

  • Preprocessor statement must be at the start of program file.
  • Preprocessor directive definition start with # .

Examples :

#define XYZ 10  // to define some constaint 
#include <stdio.h> // to include some file 

int main()
{
   printf("%d \n", XYZ); // it will print XYZ value
   return 0;
}

Available Preprocessor

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