if else shortcut c++ code example
Example 1: c++ short if
(condition) ? (if_true) : (if_false)
Example 2: shorten if condition c++
(condition) ? (if_true) : (if_false)
Example 3: short for if
#include <iostream>
//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;
}