title | description | ms.date | f1_keywords | helpviewer_keywords | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Equality operators: == and != |
The C++ standard language equal-to and not-equal-to operator syntax and use. |
08/09/2024 |
|
|
expression
==
expression
expression!=
expression
The equal-to operator (==
) returns true
if both operands have the same value; otherwise false
.
The not-equal-to operator (!=
) returns true
if the operands don't have the same value; otherwise false
.
In C and C++, not_eq
can be used as alternative to !=
. For more information, see not-eq
.
#include <iostream>
int main()
{
int x = 1, y = 1, z = 2;
if (x == y)
{
std::cout << "Equal\n";
}
if (x != z)
{
std::cout << "Not equal\n";
}
}
Equal
Not equal
not-eq
Operator overloading
Expressions with binary operators
C++ built-in operators, precedence; and associativity
C relational and equality operators