Preprocessor Directives and Macros in C
The C preprocessor provides directives and macros for code preprocessing before compilation. Macros allow you to define reusable code snippets, while directives control compilation and inclusion of code from other files.
#include <stdio.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define PI 3.14159
#ifdef DEBUG
#define DEBUG_PRINT(...) printf(__VA_ARGS__)
#else
#define DEBUG_PRINT(...)
#endif
int main() {
int num1 = 10;
int num2 = 20;
int max = MAX(num1, num2);
printf("Maximum: %d\n", max);
double circleArea = PI * 2.5 * 2.5;
printf("Circle area: %.2f\n", circleArea);
DEBUG_PRINT("Debug mode is enabled\n");
return 0;
}
No comments:
Post a Comment