This page contains information about using C++ conditional operator. It is not intended to teach you how to write your code, only as a quick check reference sheet.
It is a ternary operator (takes 3 operands)
Syntax: Expression1 ? Expression2 : Expression3;
Execution: Expression1 is evaluated. If Expression1 is TRUE, then the resulting value is the value of Expression2, else the resulting value is the value of Expression3.
Classic Example: Set a variable to the max of two variables
- max = (a > b) ? a : b; //can also be written as an IF statement
Another classic example: y = (y >= 0) ? y : -y; //(abs)