C++ Program to Find the Maximum Value using Macros

bookmark

#include <iostream>
#define MAX(a, b) (a > b ? a : b)
 
int main()
{
    int a = 10, b = 20, c = -30;
 
    std::cout << "MAX(10, 20) = " << MAX(a, b)
              << std::endl;
    std::cout << "MAX(-30, 20) = " << MAX(c, b)
              << std::endl;
}

 

Output:
Maximum of 10 and 20 = 20
Maximum of -30 and 20 = 20