C Procecessor Directive : #define

The #define preprocessor directive is used to define constant/identifier and a value that is substituted for that constant/identifier. The syntax is :
 #define micro_identifier value
Where :
  • micro_identifier is the name of the constant.
  • value is the value of constant
Example :
#define PI 3.14
C program example :
#include <stdio.h>

#define PI 3.14

int main() {
  int radious = 5;
  float area;

  area = 2*PI*(radious*radious);

  printf("Area : %.2f\n", area);
  return 0;
}
Output :

Area : 157.00

Example 2 :
#include <stdio.h>

#define GREATERTHEN >

int main() {
  int num = 5;

  while(num GREATERTHEN 0) {
    printf("%d\n", num);
    num--;
  }

  return 0;
}
Output :

1
2
3
4
5


Next : C Language Tutorials List