if else in one line c++ code example
Example 1: single line if c++
a = (x > y) ? z : y;
/* Same as */
if (x > y)
{
a = z;
}
else
{
a = y;
}
Example 2: c++ short if
(condition) ? (if_true) : (if_false)
a = (x > y) ? z : y;
/* Same as */
if (x > y)
{
a = z;
}
else
{
a = y;
}
(condition) ? (if_true) : (if_false)