one line if statement 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: one line if statement c++
x = condition ? expression1 : expression2
// Example:
double x = (1 > 0) ? 10 : 20; // put any value