Relational Operators in C++

- February 12, 2018
A relational operator is a
programming language construct or operator that tests or defines some kind of relation between two entities . These include numerical equality (such as 8 = 8) and inequalities (such as 7 ≥
4).
C++ relational operators

In C++, there are six basic relational operators that are used to compare two values of the same data type. The relational operator returns True (1) or false (0) as a result of comparison between two values. These operators are used to specify conditions in the programs. In the following table, operator symbols, meaning and purpose are described.
Operator Meaning Description
== Equal to This operator returns true if both values equal, otherwise returns false.
!= Not equal to Returns true if both values are different, otherwise returns false.
> Greater than Returns true if first value is greater than second value, otherwise returns false.
< Less than Returns true if first value is less than second value, otherwise returns false.
>= Greater than or Equal to Returns true in the both case if first value is equal to or greater than, otherwise returns false.
<= Less than or Equal to Returns true if first value is less than or equal to second value, otherwise returns false.
Relational operators can be used to compare numeric quantities (both integer and float values). The values being compared may be constant value or variables or results of expressions.

The type of values on both sides of relational operator must be same data type, if these values that are being compared are not same data type, an error may occur and program will stop.