Opening the book…
In C++ programming, followings are commonly used relational operators:
| Operator | Name | Example (radius=5) | Result |
| < | less than | radius<0 | false |
| <= | less than or equal to | radius<=0 | false |
| > | greater than | radius>0 | true |
| >= | greater than or equal to | radius>=0 | true |
| == | equal to | radius==5 | true |
| != | not equal to | radius!=5 | false |
We use above relational operators along with numbers, variables, expressions to form a relational statement such as followings:
a>5
i<=10
a!=0
Each relational statement possesses a Boolean value, which is either true or false (1 or 0 equivalently) depending on the logical correctness of the statement. If a relational statement contains variables, the Boolean value of this statement usually depends on the value of the variable. For example, the value of the relational statement
m>5
depends on the value of the variable m. If the value of m is 11, then the value of the statement is true or 1, if the value of m is 0, the value of this relational statement is false or 0.
In C++, a relational statement normally does not appear in a line of code all by itself such as
a=5>2;
A relational statement is often used in a C++ program as a condition in a selection or a looping statement.
This page titled 3.1: Relational Operators and Relational Statements was last modified on Wed, 24 Dec 2025 20:37:21 GMT and is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Jin He.
The book could not be loaded just now.