O'Reilly logo

C Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required