The conditional operator   ? :

  • The conditional operator (denoted as:   ? : ) is the only ternary (3 operands) operator in C (and in Java).

  • Syntax of the conditional operator:

     expr1 ? expr2 : expr3 
    
     Effect:
    
        if  expr1  is  true  (i.e.: non-zero)
           return: expr2
        else
           return: expr3