Logical Operators

I l @ ve RuBoard

Logical Operators

Logical operators normally take relational expressions as operands. The ! operator takes one operand. The rest take two: one to the left, and one to the right.

&& AND
OR
! NOT

Logical Expressions

expression1 && expression2 is true if, and only if, both expressions are true.

expression1 expression2 is true if either one or both expressions are true.

!expression is true if the expression is false, and vice versa.

Order of Evaluation for Logical Expressions

Logical expressions are evaluated from left to right. Evaluation stops as soon as something is discovered that renders the expression false.

Examples

6 > 2 && 3 == 3 is true.

! ( 6 > 2 && 3 == 3 ) is false.

x != 0 && 20/x < 5 The second expression is evaluated only if x is nonzero.

I l @ ve RuBoard


C++ Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 314
Authors: Stephen Prata

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net