Skip to content

Commit 612e650

Browse files
authored
Merge pull request #5642 from MicrosoftDocs/main
8/12/2024 AM Publish
2 parents 5232c3a + ae8cc9c commit 612e650

21 files changed

+463
-424
lines changed
Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
---
22
description: "Learn more about: not_eq"
33
title: "not_eq"
4-
ms.date: "11/04/2016"
4+
ms.date: 08/09/2024
55
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"]
66
api_type: ["DLLExport"]
77
topic_type: ["apiref"]
88
f1_keywords: ["ISO646/not_eq", "not_eq", "std::not_eq", "std.not_eq"]
99
helpviewer_keywords: ["not_eq function"]
10-
ms.assetid: d87ad299-8b50-4393-a57f-06f70e1f23fb
1110
---
1211
# `not_eq`
1312

14-
An alternative to the **`!=`** operator.
13+
An alternative spelling for the **`!=`** operator.
1514

1615
## Syntax
1716

@@ -21,34 +20,40 @@ An alternative to the **`!=`** operator.
2120
2221
## Remarks
2322
24-
The macro yields the operator **`!=`**.
23+
C++:
24+
- **`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.
25+
- Including `<iso646.h>` or `<ciso646>` is deprecated. You can use the alternative spelling without including any header files.
26+
- There's no alternative spelling for **`==`**.
27+
28+
C:
29+
- **`not_eq`** is an alternative spelling for **`!=`**. It is provided as a macro in `<iso646.h>`, which you must `#include`.
30+
- There's no alternative spelling for **`==`**.
2531
2632
## Example
2733
2834
```cpp
29-
// iso646_not_eq.cpp
3035
// compile with: /EHsc
3136
#include <iostream>
3237
#include <iso646.h>
3338
3439
int main( )
3540
{
36-
using namespace std;
37-
int a = 0, b = 1;
38-
39-
if (a != b)
40-
cout << "a is not equal to b" << endl;
41-
42-
if (a not_eq b)
43-
cout << "a is not equal to b" << endl;
41+
int x = 1, y = 2;
42+
43+
// not_eq is available in C++ and C
44+
// This example is for C++, so no header file is needed to use not_eq
45+
// When compiling for C, #include <iso646.h> to use not_eq
46+
if (x not_eq y)
47+
{
48+
std::cout << "Not equal\n";
49+
}
4450
}
4551
```
4652

4753
```Output
48-
a is not equal to b
49-
a is not equal to b
54+
Not equal
5055
```
5156

5257
## Requirements
5358

54-
**Header:** \<iso646.h>
59+
**Header:** `<iso646.h>` is necessary if you are compiling for C.
Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
---
22
title: "Equality operators: == and !="
33
description: "The C++ standard language equal-to and not-equal-to operator syntax and use."
4-
ms.date: 07/23/2020
5-
f1_keywords: ["!=", "==", "not_eq_cpp"]
6-
helpviewer_keywords: ["!= operator", "equality operator", "not equal to comparison operator", "equality operator [C++], syntax", "== operator", "not_eq operator", "equal to operator"]
7-
ms.assetid: ba4e9659-2392-4fb4-be5a-910a2a6df45a
4+
ms.date: 08/09/2024
5+
f1_keywords: ["!=", "=="]
6+
helpviewer_keywords: ["!= operator", "equality operator", "not equal to operator", "equality operator [C++], syntax", "== operator", "equal to operator"]
87
---
98
# Equality operators: `==` and `!=`
109

@@ -15,38 +14,41 @@ ms.assetid: ba4e9659-2392-4fb4-be5a-910a2a6df45a
1514
1615
## Remarks
1716

18-
The binary equality operators compare their operands for strict equality or inequality.
17+
The equal-to operator (**`==`**) returns **`true`** if both operands have the same value; otherwise **`false`**.\
18+
The not-equal-to operator (**`!=`**) returns **`true`** if the operands don't have the same value; otherwise **`false`**.
1919

20-
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`**.
21-
22-
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`**.
23-
24-
## Operator keyword for !=
25-
26-
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.
20+
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).
2721

2822
## Example
2923

3024
```cpp
31-
// expre_Equality_Operators.cpp
32-
// compile with: /EHsc
3325
#include <iostream>
3426

35-
using namespace std;
36-
37-
int main() {
38-
cout << boolalpha
39-
<< "The true expression 3 != 2 yields: "
40-
<< (3 != 2) << endl
41-
<< "The false expression 20 == 10 yields: "
42-
<< (20 == 10) << endl;
27+
int main()
28+
{
29+
int x = 1, y = 1, z = 2;
30+
31+
if (x == y)
32+
{
33+
std::cout << "Equal\n";
34+
}
35+
36+
if (x != z)
37+
{
38+
std::cout << "Not equal\n";
39+
}
4340
}
4441
```
4542

46-
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.
43+
```output
44+
Equal
45+
Not equal
46+
```
4747

4848
## See also
4949

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

0 commit comments

Comments
 (0)