#define : #define preprocessor are used to define macros.
The #define directive format is :
#define identifier replacement -text
- When this line appears in a file,all subsequent occurences of identifier that do not appear in string literals will be replaced by replacement - text automatically before the program is compiled.
Analyse the following examples to understand this directive
#define PI 3.1415
The string 3.1415 is replaced in every occurence of symbolic constant.
For expl : program to find the area of circle using #define
#include<stdio.h>#define PI 3.1415
main()
{
int radius ;
float area ;
printf (" Enter the radius : ");
scanf("%d",&radius);
area = PI * radius *radius ;
printf (" Area = %2f",area);
}
Output : Enter the radius : 3
Area = 28.27