The pre-processor is a program which process the source code before it passes through compiler. It operates under the control of different command lines or directives.
Pre-processor are placed in source program before the main line, it begins with symbol# in column one and do not require a semicolon at the end.
The commonly used pre-processor directives are −
The pre-processor directives are divided into three categories −
The syntax and an example is as follows −
Given below is the syntax for macro substitution directive −
#define identifier string
Example − simple macro: #define MAX 500
Macro with arguments − #define sqrt(x) x*x
Nested Macro − #define A 10
#define B A+1
The syntax and an example is as follows −
Syntax
Given below is the syntax for file inclusion directive −
#include “filename” or #include<filename>
For example,
#include<stdio.h> #include "FORM.C"
These are used to control the compiler actions. C pre=processor offers a feature called as conditional compilation, which can be used to switch on or off based on particular line or group of lines in a program.
For example, #ifdef and #ifndef