C preprocesssor

Preprocessor is the phase before compilation of source code. It translate the source code into compiler readable code.

Generally preprocessor does textual replacement in source code three ways :

1. File inclusion

2. Macro Substitution

3. Conditional Compilation


1. File inclusion :

The #include<filename.h> or #include “filename.h” statements are comes under file inclusion . Preprocessor directive searches for filename.h and includes its content in our current directory. <filename.h> will search in specific directories defined under compiler and “filename.h” will search for file in current directory only. .h specifies that the file is header file which contains library functions to be used.

2. Macro Substitution :

The preprocessor line of the form #define NAME VALUE is comes under macro substitution. In this section compiler searches for NAME in current source file and substitutes the VALUE in the place of name.

Macro NAME uses same convention used for identifier selection but it is recommended to use NAME as Capital and VALUE can be any thing string, function, integer or float.

NOTE : wrong declaration #define MAXVALUE 100; 

; must not be used for defining macro.

example :

In above code the output will be :




3. Conditional Compilation :

Conditional compilation can define whether statement to be compiled or not before compile time . But in Conditional statements in C if () else  can determine only at run time.

for conditional compilation We wiil use #ifdef, #else, #endf,   #indef ,

example :

Output of the above code :

X is Defined with Value : 100

%d bloggers like this: