The relational operators are often used to create a test expression that controls program flow. 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 1: 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:
| 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 1
Evaluate the following Boolean expressions:
- 9 < 25
- 9 < 3
- 9 > 14
- 9 <= 17
- 9 >= 25
- 9 == 13
- 9 != 13
- 9 !< 25
Solution
Answers:
- 1
- 0
- 0
- 1
- 0
- 0
- 1
- Error, the "not less than" is not a valid operator.
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.







Boolean Data Type
Data Manipulation
Bloodshed Dev-C++ 5 Compiler/IDE

"Used in the Computer Programming Fundamentals I course."