Skip to content

Repo sync for protected branch #5078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions docs/c-runtime-library/reference/not-eq.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
---
description: "Learn more about: not_eq"
title: "not_eq"
ms.date: "11/04/2016"
ms.date: 08/09/2024
api_location: ["msvcrt.dll", "msvcr80.dll", "msvcr90.dll", "msvcr100.dll", "msvcr100_clr0400.dll", "msvcr110.dll", "msvcr110_clr0400.dll", "msvcr120.dll", "msvcr120_clr0400.dll", "ucrtbase.dll"]
api_type: ["DLLExport"]
topic_type: ["apiref"]
f1_keywords: ["ISO646/not_eq", "not_eq", "std::not_eq", "std.not_eq"]
helpviewer_keywords: ["not_eq function"]
ms.assetid: d87ad299-8b50-4393-a57f-06f70e1f23fb
---
# `not_eq`

An alternative to the **`!=`** operator.
An alternative spelling for the **`!=`** operator.

## Syntax

Expand All @@ -21,34 +20,40 @@ An alternative to the **`!=`** operator.

## Remarks

The macro yields the operator **`!=`**.
C++:
- **`not_eq`** can be used as alternative to **`!=`**. The [`/permissive-`](../../build/reference/permissive-standards-conformance.md) or [`/Za`](../../build/reference/za-ze-disable-language-extensions.md) compiler option is required.
- Including `<iso646.h>` or `<ciso646>` is deprecated. You can use the alternative spelling without including any header files.
- There's no alternative spelling for **`==`**.

C:
- **`not_eq`** is an alternative spelling for **`!=`**. It is provided as a macro in `<iso646.h>`, which you must `#include`.
- There's no alternative spelling for **`==`**.

## Example

```cpp
// iso646_not_eq.cpp
// compile with: /EHsc
#include <iostream>
#include <iso646.h>

int main( )
{
using namespace std;
int a = 0, b = 1;

if (a != b)
cout << "a is not equal to b" << endl;

if (a not_eq b)
cout << "a is not equal to b" << endl;
int x = 1, y = 2;

// not_eq is available in C++ and C
// This example is for C++, so no header file is needed to use not_eq
// When compiling for C, #include <iso646.h> to use not_eq
if (x not_eq y)
{
std::cout << "Not equal\n";
}
}
```

```Output
a is not equal to b
a is not equal to b
Not equal
```

## Requirements

**Header:** \<iso646.h>
**Header:** `<iso646.h>` is necessary if you are compiling for C.
48 changes: 25 additions & 23 deletions docs/cpp/equality-operators-equal-equal-and-exclpt-equal.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
title: "Equality operators: == and !="
description: "The C++ standard language equal-to and not-equal-to operator syntax and use."
ms.date: 07/23/2020
f1_keywords: ["!=", "==", "not_eq_cpp"]
helpviewer_keywords: ["!= operator", "equality operator", "not equal to comparison operator", "equality operator [C++], syntax", "== operator", "not_eq operator", "equal to operator"]
ms.assetid: ba4e9659-2392-4fb4-be5a-910a2a6df45a
ms.date: 08/09/2024
f1_keywords: ["!=", "=="]
helpviewer_keywords: ["!= operator", "equality operator", "not equal to operator", "equality operator [C++], syntax", "== operator", "equal to operator"]
---
# Equality operators: `==` and `!=`

Expand All @@ -15,38 +14,41 @@ ms.assetid: ba4e9659-2392-4fb4-be5a-910a2a6df45a

## Remarks

The binary equality operators compare their operands for strict equality or inequality.
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`**.

The equality operators, equal to (**`==`**) and not equal to (**`!=`**), have lower precedence than the relational operators, but they behave similarly. The result type for these operators is **`bool`**.

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 don't have the same value; otherwise, it returns **`false`**.

## Operator keyword for !=

C++ specifies **`not_eq`** as an alternative spelling for **`!=`**. (There's no alternative spelling for **`==`**.) In C, the alternative spelling is provided as a macro in the \<iso646.h> header. In C++, the alternative spelling is a keyword; use of \<iso646.h> or the C++ equivalent \<ciso646> is deprecated. In Microsoft C++, the [`/permissive-`](../build/reference/permissive-standards-conformance.md) or [`/Za`](../build/reference/za-ze-disable-language-extensions.md) compiler option is required to enable the alternative spelling.
In C and C++, **`not_eq`** can be used as alternative to **`!=`**. For more information, see [`not-eq`](../c-runtime-library/reference/not-eq.md).

## Example

```cpp
// expre_Equality_Operators.cpp
// compile with: /EHsc
#include <iostream>

using namespace std;

int main() {
cout << boolalpha
<< "The true expression 3 != 2 yields: "
<< (3 != 2) << endl
<< "The false expression 20 == 10 yields: "
<< (20 == 10) << endl;
int main()
{
int x = 1, y = 1, z = 2;

if (x == y)
{
std::cout << "Equal\n";
}

if (x != z)
{
std::cout << "Not equal\n";
}
}
```

Equality operators can compare pointers to members of the same type. In such a comparison, pointer-to-member conversions are performed. Pointers to members can also be compared to a constant expression that evaluates to 0.
```output
Equal
Not equal
```

## See also

[`not-eq`](../c-runtime-library/reference/not-eq.md)\
[Operator overloading](../cpp/operator-overloading.md)\
[Expressions with binary operators](../cpp/expressions-with-binary-operators.md)\
[C++ built-in operators, precedence; and associativity](../cpp/cpp-built-in-operators-precedence-and-associativity.md)\
[C relational and equality operators](../c-language/c-relational-and-equality-operators.md)
Loading