How to create abbreviations with macros in C++

1 Answer

0 votes
#include <iostream>

// Abbreviation: macro for a constant value.
#define PI 3.141592653589793

// Abbreviation: macro for a repeated expression.
#define AREA(r) (PI * (r) * (r))

int main() {
    double radius = 5.0;

    std::cout << "Area = " << AREA(radius) << "\n";
}



/*
run:

Area = 78.5398

*/

 



answered Jul 9 by avibootz
...