about #define preprocessor directive in C language

We use #define preprocessor directive in C to create any preprocessor macro. Because sometimes we need to define a preprocessor macro. Here is also the source file which is inside our main program is compiled after the compilation of code inside the #define directive.

#define preprocessor directive is also used to define any constant of our program.

Let’s take an example of defining a constant.

#include <stdio.h>
#define RADIUS_OF_WORLD 6400

Output :


The macro name and arguments are replaced by the replacement text if we define a macro as like as the example bellow;

#define defined_macro(x, y, z) x+y+z

int define_function (int i, int j, int k){
  return(defined_macro(i, j, k));

This program will work as like as follows.

int define_function(int i, int j, int k){
  return(i + j + k);

Now, let’s see another example C program to define a macro using #define preprocessor directive.

#include <stdio.h>
#define MAX (i, j) (i>j? i:j)
int main(){
  printf("Big number between 15 and 7 is = %d\n", MAX(15, 7));
  return 0;

Output of this program will be as like as following;