Preprocessor Directives in C
Preprocessor directives are commands used by the preprocessor to perform certain actions before the compilation process. They are preceded by a # symbol and are typically used to include header files or define constants.
#include <stdio.h>
#define PI 3.14159
int main() {
double radius;
printf("Enter the radius of a circle: ");
scanf("%lf", &radius);
double area = PI * radius * radius;
printf("Area of the circle: %.2f\n", area);
return 0;
}
In this example, the #include directive is used to include the standard input/output header file. The #define directive defines a constant PI with the value 3.14159. The constant is then used in the program to calculate the area of a circle.
No comments:
Post a Comment