Equality Operators

The binary equality operators compare their operands for strict equality or inequality.

Syntax

equality-expression :

relational-expression
equality-expression == relational-expression
equality-expression != relational-expression

The equality operators, equal to (==) and not equal to (!=), have lower precedence than the relational operators, but they behave similarly.

The equal-to operator (==) returns true if both operands have the same value; otherwise, it returns false. The not-equal-to operator (!=) returns true if the operands do not have the same value; otherwise, it returns false.

Equality operators can compare pointers to members of the same type. In such a comparison, pointer-to-member conversions, as discussed in Pointer-to-Member Conversions in Chapter 3 are performed. Pointers to members can also be compared to a constant expression that evaluates to 0.