{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

The conditional expression

The conditional expression - The conditional expression The...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
The conditional expression The purpose of the conditional expression is to select one of two expressions depending on a third, boolean, expression. The format for the conditional expression is <boolean-expression> ? <expression-1> : <expression-2> If the value of the <boolean-expression> is true, the value of the conditional expression is the value of <expression-1>; if it is false, the value of the conditional expression is the value of <expression-2>. An important point is that only one of <expression-1> and <expression-2> is evaluated when evaluating the conditional expression. For example, the divide-by-zero in the following expression causes no error because it is not evaluated: true ? 7 : 7/0 Expressions <expression-1> and <expression-2> may be any expressions, as long as the have the same type (if one is wider than the other, the narrower one will automatically be promoted to the wider type). The conditional expression is known as a ternary operation , because it has three operands.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}