C Macros using #define

#include <stdio.h>

#define SQUARE(x) (x*x)
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define PRINT_MSG(msg) printf("%s\n", msg)

int main() {
    int a = 5, b = 3;

    // Example 1: SQUARE macro
    int squareResult = SQUARE(a + b); // Expands to: (a + b * a + b)
    printf("Square result: %d\n", squareResult);

    // Example 2: MAX macro
    int maxResult = MAX(a, b + 2); // Expands to: ((a) > (b + 2) ? (a) : (b + 2))
    printf("Max result: %d\n", maxResult);

    // Example 3: PRINT_MSG macro
    PRINT_MSG("Hello, Macros!");

    return 0;
}