The C processor is a macro processor which is used to compile the source code of the program (step by step) . It is not a part of the compiler. All pre-processor commands begin with the hash symbol (#).

The C pre-processor provides various facilities that are:

  • Inclusion of header
  • Macro expansion
  • Conditional compilation
  • Line control


Preprocessor Syntax/Description
Macro Macro is used to define the constant value and data types.

Syntax: #define

Header file inclusion The source code of the file “file_name” is included in the main program at the specified place.

Syntax: #include <file_name>

Conditional compilation It is used to set of commands in source program.

Syntax: #ifdef, #endif, #if, #else, #ifndef

Other directives #undef is used to defined a macro variable and #Pragma is used to call a function before and after main function.

Syntax: #undef, #pragma


C language, there are various stages of the execution process. The given following diagram will help you:


There are following important pre-processor directories in C language.

Directive Description
#define Substitutes a pre-processor macro.
#include It is used to inserts a particular header from another file.
#undef It is used to undefine a preprocessor macro.
#ifdef It is used to return true if this macro is defined.
#ifdef It is used to return if this macro is defined.
#if It is used to check compile time condition.
#else The alternative for #if.
#elif #if and #else in one statement.
#endif It is used to end pre-processor conditional.
#error It is used to print an error message on stderr.
#pragma Issues special command to the compiler, using a standardized method.


Example: 1

Example 2


C Macros

A macro is a name which stands for a fragment of code. Before using macro we must define it with ‘#define’ directive. It is the name of a macro.

There are two types of macros.

  1. Object-like macros
  2. Function-like macros 


  1. Object-Like Macros:

The object-like macro is an identifier that is replaced by value. It is widely used to represent numeric constants.



  1. Function like Macros:

Function like macros is used as a function call. Let us consider an example.

Here MAX is the macro name.

There are some predefined macros :

Predefined Macros Description
_DATE_ It is defined as the current date with “MMM DD YYY” format.
_TIME_ It is defined as current time with “HH:MM:SS” format.
_FILE_ It contains the current filename as a string literal.
_STDC_ It is defined as 1 when compiler compiles with the ANSI standard.
__STDC_VERSION__ It is defined as standard’s version
_GNUC_ It is defined if and only if this is  GNU C. etc

Example of Macros



C #define and #include.

C #defined:

It defines constant value. It can be any of the basic data types.


Example: 1






It is used to paste the code of given file into the current file. We can use system-defined and used-defined header files.

There are two types of #include directive.

  1. #include< filename>
  2. #include ”filename”




C #undef:

It is used to check undefined the constant or macro. It is defined by #define.


Example 1:


Example 2:



#ifdef, #else and #endif

The ‘#ifdef’ directive is used to check whether the macro is defined or not. If it is defined then, ‘if’ clause statements are included in the source code.

Otherwise “else” clause statements are included in the source file for compilation and execution.

Example : #ifdef



C #Pragma:

The C #Pragma is used to call a function before and after the main function. It also provides additional information to the compiler.

There are several types of pragmas in GCC compiler.

  • AArch64 Pragmas
  • ARM Pragmas
  • M32C Pragmas
  • MeP Pragmas
  • RS/6000 and PowerPC Praglmas
  • S/390 Pragmas:
  • Darwin Pragmas:
  • Solaris Pragmas: etc.





Pin It on Pinterest

Share This