The Conditional Expression Operator
Previous Topic  Next Topic 

The Conditional Expression uses the ? and : operators and takes the form:


A ? B : C


Which can be read as:  If A is TRUE then the expression takes the value B else it take the value C.


For example:


b=(a<0)? -a: a;    // Sets b to the positive value (modulus) of a

b=(a > 255)?255:a; // set b to the value of a up to the limit 255