×

C++ Tutorial

C++ Data types

C++ Operators & Keywords

C++ Conditional Statements

C++ Functions

C++ 'this' Pointer, References

C++ Class & Objects

C++ Constructors & Destructors

C++ Operator overloading

C++ 11 (Advance C++)

C++ Preparation

C++ Header Files & Functionsr

Data Structure with C++

C++ - Miscellaneous

C++ Programs

C++ 'not' Keyword with Examples

C++ | 'not' keyword: Here, we are going to learn about the 'not' keyword which is an alternative to Logical NOT operator.
Submitted by IncludeHelp, on May 16, 2020

C++ 'not' Keyword

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

The not keyword returns 1 if the result of the given condition is 0, and it returns 0 if the result of the given condition is 1.

Syntax

not operand;

Here, operand is the operand.

Sample Input and Output

Input:
a = 10;
b = 20;
    
result = not(a < b);

Output:
result = 1

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

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

#include <iostream>
using namespace std;

int main()
{
    int num = 20;

    if (not(num >= 10 and num <= 50))
        cout << "true\n";
    else
        cout << "false\n";

    if (not(num >= 20 and num <= 50))
        cout << "true\n";
    else
        cout << "false\n";

    if (not(num > 50 and num <= 100))
        cout << "true\n";
    else
        cout << "false\n";

    return 0;
}

Output

false
false
true

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.