What is preprocessor in c programming language?

Preprocessor in c programming language
Preprocessor in c.


The C preprocessor is a micro processor that is used by compiler to transform our code before compilation. it is called micro preprocessor because it allows us to add macros.

All preprocessor directives Starts with hash (#) Symbol.

#define Preprocessor :

A macro is a Segment of code which is replaced by the Value of macro. Macro is defined by #define directive

Syntax :

#define token value

There are two types of 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. 

#define PI 3.1415

Here, PI is the macro name which will be replaced by the value 3.14.

2. Function-like Macros :- The function-like macro looks like function Call.

#define MIN(a, b) ((a)<(b)? (a):(b))

Here, MIN is the macro name.

#include Preprocessor :

The #include preprocessor directive is used to paste code of given file into Current file.
It is used to include System-defined and user-defined header files. If included file is not found, compiler renders error.

It has three variants :

1. #include<file> :

This variant is used for System header files. It Searches for a file named file in a list of directories Specified by you, then in a Standard list of System directories.

2. #include"file" :

This variant is used for header files of your own program. It Searches for a file named file in the Current directory, then in the same directories used for System header files.

3. #include anything else :

This variant is called Computed #include Any #include directive whose argument does not fit the above two forms is a computed include.