Related Articles
























































C++ 'Not_Eq' Keyword With Example

Prashant | Wed, 05 Aug, 2020 | 102

CPP 'not_eq' Keyword with Example

"not_eq" is an inbuilt keyword that has been around since at least C++98. It is an alternative to != (NOT EQUAL TO) operator and it mostly uses with the conditions.

The not_eq keyword returns 1 if operand_1 is not equal to the operand_1, and it returns 0 if operand_1 is equal to the operand_2.

Syntax:

    operand_1 not_eq operand 2;

Here, operand_1 and operand_2 are the operands.

Example:

    Input:
    a = 10;
    b = 20;
    
    result = a not_eq b;

    Output:
    result = 1

C++ example to demonstrate the use of "not_eq" keyword

// C++ example to demonstrate the use of 
// 'not_eq' operator.

#include <iostream>
using namespace std;

int main()
{
    int a = 10;
    int b = 20;

    cout << "a: " << a << endl;
    cout << "b: " << b << endl;

    if (a not_eq b)
        cout << a << " is not equal to " << b << endl;
    else
        cout << a << " is equal to " << b << endl;

    a = 20;
    b = 20;

    cout << "a: " << a << endl;
    cout << "b: " << b << endl;

    if (a not_eq b)
        cout << a << " is not equal to " << b << endl;
    else
        cout << a << " is equal to " << b << endl;

    return 0;
}

Output:

a: 10
b: 20
10 is not equal to 20
a: 20
b: 20
20 is equal to 20

Related Articles
























































0 comments
Leave a comment