C++: ternary operators
The ternary operators in C uses conditional operations.
  • How it works ?
    • Explaining with logical blocks
      if(a>b){ var1 = a;}
      else if(b>a){ var1 = b;}
      else { cout<<"a==b" ;}
    •  #define get_param(x1,y1) ((x1)>(y1)?(x1):(y1))
To define preprocessor macros we can use #define. It's format is:
#define identifier replacement

#include <iostream>
#define team_roster 18
#define get_param(x1,y1) ((x1)>(y1)?(x1):(y1))
using namespace std;
int main()
int n1[team_roster];
int n2 = team_roster;
cout << "Welcome to C++!\n" << n1 <<"\n" << n2<<endl;
int x=5, y, z;
y= get_param(x,12);
z= get_param(x,2) ;
cout << y << endl;
cout << get_param(7,x) << endl;
cout << z << endl;
return 0;

In the above example we used ternary operator " #define get_param(x1,y1) ((x1)>(y1)?(x1):(y1))". While defining preprocessor, #define uses two parameters to define function macros:
  • in the above example z= get_param(x,2) ; prints 5 because in this condition x is more than the other variable.
  •  the same way y= get_param(x,12); prints 12 because the second argument is more than the first argument.
  • The operator ? decides the out put arguing over > operator.