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
Background image of page 1

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

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

This note was uploaded on 07/07/2008 for the course CS 101 taught by Professor Gries during the Spring '08 term at Cornell University (Engineering School).

Page1 / 2

The conditional expression - The conditional expression The...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online