Prashant | Wed, 05 Aug, 2020 | 108
"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' 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