#define Preprocessor Directive in C | Simple Substitution Macro

Simple Substitution Macro : #define Preprocessor in C

Syntax

#define macro_identifier value

Note

  • #define Preprocessor defines a identifier and a value that is substituted for identifier each time it is encountered in the source file
  • Generally macro-identifier is written in the Capital Letter to distinguish it from other variables.
  • Its like a name-value Pair.

Examples :

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

Live Example :

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

#include<stdio.h>
#define LESSTHAN <
int main()
{
int a = 30;
if(a LESSTHAN 40)
        printf("a is Smaller");
return(0);
}

Step 2 : Program is processed by Pre-processor

int main()
{
int a = 30;
if(a < 40)
        printf("a is Smaller");
return(0);
}

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;