In this chapter we will learn about Preprocessors in C.

What are preprocessors in c?

Preprocessors are a separate step in compilation process. They are included in the program before it is compiled. For example, header files and macros. These instructs the compiler to do required preprocessing before compiling the program.

All the preprocessing starts with a # symbol. For example -

#define PI 3.14

Below are some of the common preprocessor directives

Sr. No.





Used to insert header files in the program.



Used to define a preprocessor macro.



Used to undefine a preprocessor macro.



This is to check whether macro is defined, if defined it will return true.



This is to check whether macro is not defined, if not defined it will return true.



This indicates the end of conditional statement of preprocessor.

Now Lets uderstand them with some examples:


As we know from above table that this is used to include header file.

Header file:

You have may have seen stdio.h in many c programs, this is a system header file that has some functions defined such as printf() , scanf() and etc.

All the header files have .h file extension.

#include is used in two ways, are :-

#include <header_file>

This is used when we are using system header files.

#include "header_file"

This is used when we are using custom or user defined header files.

File - include_example.c
#include<stdio.h>  //System header file
#include"add.h"   //Custom header file

void main(){
	int a,b;
	a = 55;
	b = 45;
	* calculating sum of two number
	* using add function
	* defined in custom header file add.h

	* Printing
	* Sum found :)
	* using printf()
	printf("Sum found :) \n");
File - add.h
void add(int a, int b)
    printf("Sum is = %d\n", a + b);

This header file declared is only for learning purpose and idealy its a bad practice to define function definiton in header files.

Sum is = 100
Sum found :)

Note: Here include_example.c and add.h are in same directory.


This is used to define macros in a c program.


A macro is a name given to a fragment of code. Whenever a macro is used in a program the macro is replaced with its value. For example:

File - macro_define.c
#define PI 3.141592
void main(){
    printf("The value of pi is %f",PI);
The value of pi is 3.141592

#ifdef,#ifndef,#undef and #endif

Below is an example to illustate the use of above preprocessors:

File - using_pi.c
#define PI 3.141592
#define RADIUS 45
#undef RADIUS //it will undefine RADIUS
void main(){
    #ifdef RADIUS // execute when RADIUS is defined
        printf("Circumference is %f",(PI*RADIUS));
    #ifndef RADIUS // execute when RADIUS is not defined
        printf("The value of pi is %f",PI);
The value of pi is 3.141592

Now if we remove #undef RADIUS from the above example then the output would be:

Output without #undef
Circumference is 141.371640

In the next chapter, we will learn about command line arguments