A c program is compiled in a compiler source code is processed by a program called pre-processor.This process is calles preprocessing. Commands used in pre-processor are called pre-processor directives and they begin with ’#’ symbol.
Like - #define , #include , #ifdef , #undef ,
#ifndef , #if , #else , #elif , #endif , #error , #pragma etc.
Example of pre-processor directive
#include<iostream.h>
#include<conio.h>
#define MUL(x) x*x*x
void main(){
int i=2;
clrscr();
i=MUL(++i);
cout<<i;
getch();
}
Output
125
Stringizing operator
The operation ‘#’ is
know as stringizing operator in c.It is used in conjunction with #define
directive. Stringizing operator ‘#’ is used to turn the argument into quoted
string.
#include<iostream.h>
#include<conio.h>
#define print(s) printf(#s)
void main(){
clrscr();
cout<<print("Hello");
getch();
}
Output
“Hello”
Token pasting (##)
The token pasting
operator is a pre-processor operator. It sends commands to compiler to add or
concatenate two token into one string. We use this operator at the macro
definition.
#include<iostream.h>
#include<conio.h>
#define combine(x,y) x##y
void main(){
int ab=20;
clrscr();
cout<<combine(a,b);
getch();
}
Output
20
#include<iostream.h>
#include<conio.h>
#define N 5
void main(){
#undef N
clrscr();
#ifdef N
cout<<N;
#endif
getch();
}
Output
Nothing result
0 Comments