Pre-processors in C

Pre-processors in C :

Pre-processors are one of the powerful tools of c programming language. These are the instructions which are performed by the compiler before actual compilation.

All the pre-processor directives command are written beginning with #.  # is used to differentiate a pre-processor directive from rest of the programming code.

Following are the pre-processors directives used in c :

include :

This instructs to include the header files in a program(copy the code of header file into another file).
Syntax:
#include<header_file_name>
This searches for file in standard library of c.
#include”header_file_name”
This searches for file in a current directory as well as standard library.
e.g.
#include”stdio.h”

define :

It is used to define a constant and macros in a c programming.
Syntax
#define token value
#define PI 3.14
It replace PI with 3.14 wherever written in program.

undef :

This are used to undefine the constants and macros. It limits the scope of the constants and macros defined by define preprocessor.

Syntax:
#undefine token

ifdef & endif :

ifdef includes the code between endif or else and itself if the macro is defined. endif ends the conditional preprocessor.
Syntax:
#ifdef macroname

#endif

ifndef :

ifndef includes the code between endif or else and itself if the macro is not defined. endif ends the conditional preprocessor.
Syntax:
#ifndef macroname

#endif

if & else :

if tests for compile time condition and else is for its alternative.
Syntax:
#if
….
#else
…..

elif:

It represents else and if staements in a combined form. It gives nested if else.
Syntax:
#if

#elif

#elif

#else
..

error :

It is used to display error message.
Syntax:
#error “error_message”

pragma :

It is used to issue some compiler specific command.
e.g.
#pragma startup function1()
#pragma end function2()

The above two lines will run function1() at just start of main() and function2() just before end of main().