Macro Expansion : Macro Expansion « Development « C++ Tutorial






#include <iostream>
 
 #define CUBE(a) ( (a) * (a) * (a) )
 #define THREE(a) a * a * a
 
 int main()
 {
     long x = 5;
     long y = CUBE(x);
     long z = THREE(x);
 
     std::cout << "y: " << y << std::endl;
     std::cout << "z: " << z << std::endl;
 
     long a = 5, b = 7;
     y = CUBE(a+b);
     z = THREE(a+b);
 
     std::cout << "y: " << y << std::endl;
     std::cout << "z: " << z << std::endl;
     return 0;
 }
y: 125
z: 125
y: 1728
z: 82








5.18.Macro Expansion
5.18.1.function macro
5.18.2.standard macro names: __LINE__, __DATE__, __cplusplus
5.18.3.Macro Expansion