Pre-processor directive

 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<stdio.h>

#include<conio.h>

#define MUL(x) x*x*x

void main(){

            int i=2;

            clrscr();

            i=MUL(++i);

            printf("%d",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.

Example of stringizing operator 

#include<stdio.h>

#include<conio.h>

#define print(s) printf(#s)

void main(){

            clrscr();

            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.

            x ## y – xy

Example of token pasting

#include<stdio.h>

#include<conio.h>

#define combine(x,y) x##y

void main(){

            int ab=20;

            clrscr();

            printf("%d",combine(a,b));

getch();

}

Output

        20