c++ short if
(condition) ? (if_true) : (if_false)
Source: stackoverflow.com
conditional operator in cpp
//(expression 1) ? expression 2 : expression 3 //If expression 1 evaluates to true, then expression 2 is evaluated. int x, y = 10; x = (y < 10) ? 30 : 40; cout << "value of x: " << x << endl; //prints 40
c++ ternary operator
#include <iostream> int main() { int value = (1 > 0 ? 12 : 41); /* if 1 > 0 then value is 12, else 41 */ int val2 = (1 > 0 ? (2 > 4 ? 42 : 45) : 41); // nested }