Write a c program to demonstrate pre-processor directives Macros
#include <stdio.h>
// Define a macro for a constant
#define PI 3.14159
// Define a macro for a function-like macro
#define SQUARE(x) ((x) * (x))
// Conditional compilation
#define DEBUG 1
int main() {
// Using the constant macro
printf("Value of PI: %f\n", PI);
// Using the function-like macro
int num = 5;
printf("Square of %d: %d\n", num, SQUARE(num));
// Conditional compilation
#if DEBUG
printf("Debug mode is ON\n");
#else
printf("Debug mode is OFF\n");
#endif
return 0;
}
Comments
Post a Comment