Conditional operator

                                             

                                             Condition operator


The Conditional operator (?:) is a ternary operator (it takes three operands)the condition operator work as follows:-

  • The first operand is implicity converted to bool(true or false) It is evaluated and all side effects are completed before continuing.
  • The conditional operator allows you to define a condition that returns a Boolean value. In addition to the condition, two expressions are provided. Only one of these expressions will be evaluated when the program is running, being selected according to the result of the condition.
  • If the first operand  evaluates to true ( 1 ) or true, the second operand is evaluated.
  • If the first operand evaluates to false ( 0 ) or false, the third operand is evaluated.
 

Examples:-

 
Z=(a>b)?a:b;

// condition ? true-expression : false-expression


Comments

Popular posts from this blog