short for if code example
Example 1: short for if
#include
//Another variation:
a == 1 ? std::cout << "1" : (a == 2 ? std::cout << "2" : a = 3);
//This is the same as:
if(a == 1)
{
std::cout << "1";
}
else if (a == 2)
{
std::cout << "2";
}
else
{
a = 3;
}
Example 2: c++ ternary statement
x = condition ? expression1 : expression2
// Example:
double x = 1 > 0 ? 10 : 20; // put any value