You are here

Overview of the Relational Operators

19 January, 2016 - 11:41

The relational operators are often used to create a test expression that controls program fow. This type of expression is also known as a Boolean expression because they create a Boolean answer or value when evaluated. There are six common relational operators that give a Boolean value by comparing (showing the relationship) between two operands. If the operands are of different data types, implicit promotion occurs to convert the operands to the same data type.

Definition 11.5: relational operator

An operator that gives a Boolean value by evaluating the relationship between two operands. Operator symbols and/or names vary with different programming languages. The C++ programming language operators with their meanings are:

Table 11.2 Boolean expressions

C++ Operator

Meaning

<

less than

>

greater than

<=

less than or equal to

>=

greater than or equal to

==

equality (equal to)

!=

inequality (not equal to)

Exercise 11.3.1

Evaluate the following Boolean expressions:

  1. 9 < 25
  2. 9 < 3
  3. 9 > 14
  4. 9 <= 17
  5. 9 >= 25
  6. 9 == 13
  7. 9!= 13
  8. 9!< 25

The answers to Boolean expressions within the C++ programming language are a value of either 1 for true or 0 for false.

Be careful. In math you are familiar with using this symbol = to mean equal and =/ to mean not equal. In the C++ programming language the =/ is not used and the symbol means assignment.