#define Preprocessor Directive

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

In this tutorial we will be learn how to use #define preprocessor directive in C programming.In C Programming, we can define constants using the #define preprocessor directive.

#define preprocessor directive

It is also called as simple substitution macro as it simply removes the occurrences of the constant and replace them using the expression


#define macro_identifier value

where –

Syntax part Explanation
#define It is preprocessor directive used to define constant
macro_identifier It is constant used in the program which we wish to declare using #define
value It is value of the constant

Important Note

  1. #define Preprocessor defines a constant/identifier and a value that is substituted for identifier/constant each time it is encountered in the source file
  2. Generally macro-identifiers/constant defined using #define directive are written in the capital case to distinguish it from other variables.
  3. constants defined using #define directive are like a name-value pair.


#define PI 3.142
#define TRUE 1
#define AND &&
#define LESSTHAN <
#define MESSAGE "welcome to C"

In this case –

Constant Value of constant Expression
PI 3.142 Each occurrence of PI will be replaced by 3.142
TRUE 1 Each occurrence of TRUE will be replaced by 1
LESSTHAN < Each occurrence of LESSTHAN will be replaced by >
MESSAGE welcome to C Each occurrence of TRUE will be replaced by 1

Live Example :

Step 1 : program.c [Program written by Programmer]

#define LESSTHAN <

int main()
int a = 30;
if(a LESSTHAN 40)
        printf("a is Smaller");


Step 2 : Program is processed by Pre-processor

int main()
int a = 30;
if(a < 40)
        printf("a is Smaller");

Step 3 : Program is processed by Compiler

a is Smaller

Precautions to be Taken while Writing Simple Preprocessor

  • Do not Write Semicolon After #define Statement.
#define MAX 20;