Relational Operators in C++
There are four relational operators in C Plus Plus (C++). They are:
|<=||less than or equal to|
|>=||greater than or equal to|
These operators all fall within the same precedence group, which is lower than the arithmetic and unary operators. The associativity of these operators is left to right.
Closely associated with the above mentioned relational operators are the following two equality operators:
|!=||not equal to|
The equality operators fall into a separate precedence group beneath the relational operators. These operators also have a left-to-right associativity.
These six operators are used to form logical expressions, which represent conditions that are either true or false. The resulting expressions will be of type integer, since true is represented in C++ by the integer value 1 and false by the value 0.
Suppose that a, b and c are integer variables whose values are 1, 2 and 3 respectively. Several logical expressions involving these variables are shown below:
|a < b||true||1|
|(a + b) >= c||true||1|
|(b + c) > (a + 5)||false||0|
|C != 3||false||0|
|b == 2||true||1|
[…] Relational operators […]