Ternary Operator
âââ True âââ
Result = Condition ? Exp1 : Exp2;
ââââââ False ââââââ
int x = 3, y = 5, max;
max = (x > y) ? x : y;
// Outputs: 5
std::cout << max << std::endl;
int x = 3, y = 5, max;
if (x > y) {
max = x;
} else {
max = y;
}
// Outputs: 5
std::cout << max << std::endl;
Comments