C++ 'not' Keyword with Example

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

"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.

Example:

    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

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.