THE CONDITIONAL OPERATOR

·

Conditional operator is (?:) A expression that makes use of the conditional operator is called a conditional expression

for e.g. expression 1? expression 2 : expression 3

When evaluating a conditional expression, expression 1 is evaluated first. If the expression 1 is true then expression 2 is evaluated and this becomes the value of conditional expression However, if expression 1 is false then expression 3 is evaluated and this becomes the value of the conditional expression e.g. In the conditional expression shown below suppose f and g are floating point variables. The conditional expression is

(f <>

It takes the value f if f is less than g otherwise the conditional expression takes on the value of g. In other words conditional expression returns the value of the smaller of the two variables

About Me

Blog Archive