#define is preprocessor command used to define constants and aliases. Look at this example:
Error : File not found.
Quote : Hello World!
Preprocessor step is performed before compilation and it will change the actual source code to below code. Compiler will see the program as below one:
Know more about C
#include<stdio.h>
#define PI 3.14
#define ERROR_1 "File not found."
#define QUOTE "Hello World!"
main()
{
printf("Area of circle = %f * diameter", PI );
printf("\nError : %s",ERROR_1);
printf("\nQuote : %s\n",QUOTE);
system("pause");
}
Output results:
Area of circle = 3.140000 * diameterError : File not found.
Quote : Hello World!
Preprocessor step is performed before compilation and it will change the actual source code to below code. Compiler will see the program as below one:
#include<stdio.h>
main()
{
printf("Area of circle = %f * diameter", 3.14 );
printf("\error : %s","File not found.");
printf("\nQuote : %s","Hello World!\n");
system("pause");
}
Final Word
In brief #define allows us to define symbolic constants. We usually use uppercase names for #define variables. Pay attention that we do not use ';' after preprocessor statements.Know more about C
0 comments