Relational Operators
Relational operators allow us to compare values with one another. We could, for example, check whether one value was greater than another, or if two values were equal. These operators not only work on integer values but also on collections and objects. There are two fundamental relationships that are often checked for: equality and comparison.
Equality
The relational operators that are used to determine the equality of two values are ==
and !=
; that is, equal and not equal, respectively. A value is placed on either side of the operators, referred to as LHS on the left and RHS on the right, and it's these two values that are compared. A single Boolean value is returned that denotes whether the equality check was true or not.
The two operators can be used as follows:
// Relational operators. Equality. #include <iostream> #include <string> int main() { int myInt1 = 1; int myInt2 = 1; ...