Chapter_04 copy copy.pptx
Document Details
Uploaded by IndebtedOwl
2017
Tags
Full Transcript
4.7 Logical Operators Are used to create relational expressions from other relational expressions Operator Meaning Explanation && AND New relational expression is true if both...
4.7 Logical Operators Are used to create relational expressions from other relational expressions Operator Meaning Explanation && AND New relational expression is true if both expressions are true || OR New relational expression is true if either expression is true Reverses the value of an expression; true ! NOT expression becomes false, false expression becomes true Copyright © 2017 Pearson Education, Ltd. 4-1 Logical Operator Examples int x = 12, y = 5, z = -4; (x > y) && (y > z) true or 1 (x > y) && (z > y) false or 0 (x 6) && (7 > 8) is true because AND is evaluated before OR Copyright © 2017 Pearson Education, Ltd. 4-4 More on Precedence Highest arithmetic operators relational operators Lowest logical operators Example: 8 < 2 + 7 || 5 == 6 is true Copyright © 2017 Pearson Education, Ltd. 4-5 Checking Numeric Ranges with Logical Operators Used to test if a value is within a range if (grade >= 0 && grade