C Tutorial
Control statement
C Loops
C Arrays
C String
C Functions
C Structure
C Pointer
C File
C Header Files
C Preprocessors
C Misc
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
main(){
printf("%d\n",RADIUS_OF_WORLD);
}
Output :
6400
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;

Previous page:Â #include preprocessor directive
Next page:Â #undef preprocessor directive