macros

C Macros

C Macros

Macros are powerful tools in C that allow you to define reusable code snippets and constants that can be substituted by the preprocessor.

Defining Macros

#include 

#define PI 3.14
#define AREA(radius) (PI * radius * radius)

int main() {
    float radius = 5.0;
    printf("Area of circle: %.2f\n", AREA(radius));
    return 0;
}
    

This program defines a macro PI and a macro function AREA that calculates the area of a circle based on a given radius.