Relational operators have left to right associativity. Left to right associativity means that when two operators of same precedence are adjacent, the left most operator is evaluated first.
Relational OperatorsMeaning>Greater than=Greater than or equal to yx == y
Note: It can be easy to forget that equal to is “==” and not “=” which is assignment. In many cases, the compiler won’t note this as an error because x==y and x=y are both valid expressions.
What is the result of a relational expression?
Relational expressions are Boolean expressions and thus are equal to either true or false.
How a program treats true and false
C++ programs store true and false in memory as numbers.
false
is stored as 0
true
is stored as 1
Relational operator precedence and relationship to the other operators
Note how the relational operators rank in precedence to the mathematical and assignment operators. Also, note that the less than/greater than operators have higher precedence than the equal/not equal relational operators.
Precedence highest to lowest[ ]*, /, %+, ->, >=,