Simple conditional operations can be carried out with the conditional operator (? :).An expression that makes use of the conditional operator is called a conditional expression.
A conditional expression is written in the form
expression1 ? expression2 : expression3
When evaluating a condition expression,expression1 is evaluated first.If expression1 is true,then espression2 is evaluated and this becomes the value of the conditional expression.However,if expression1 is false,then espression3 is evaluated and this becomes the value of the conditional expression.
e.g In the conditional expression shown below,assume that i is an integer variable.
(i<0) ? 0 : 10
The expression (i<0) is evaluated first.If it is true (i.e if the value of i is less than zero) the entire conditional expression takes on the value 0.Otherwise,the entire conditional expression takes on the value 10.
Monday, December 7, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment