Lecture 6
Lecture 6
Structured Programming
Lecture 6 – Relational , Logical and Bitwise
Operators
Relational and Equality Operators
• The relationships can be expressed in C++ by using the relational operators. These
operators are listed in the following table and assume variable A holds 10 and
variable B holds 20, then:
Here there are some examples:
• ( 7 == 5 ) // evaluates to false.
• ( 5 > 4 ) // evaluates to true.
• ( 3 != 2 ) // evaluates to true.
• ( 6 >= 6 ) // evaluates to true.
• ( 5 < 5) // evaluates to false.
Also, instead of using only numeric constants, we can use any valid
expression, including variables.
Suppose that a=2, b=3 and c=6,
• ( a == 5 ) // evaluates to false since a is not equal to 5.
• ( a * b >= c ) // evaluates to true since (2*3 >= 6) is true.
• ( b + 4 > a * c ) // evaluates to false since (3+4 > 2*6) is false.
• ( ( b = 2 ) == a ) // evaluates to true.
Logical Operators
• The logical expression is constructed from relational expressions by
the use of the logical operators not(!), and(&&), or(||)
Example 1: Assume: a = 4, b = 5, c = 6. find the following expression: