C ++'not'关键字和示例
“not”是一个内置关键字,至少从C++98起就出现了。它是替代!(逻辑非)运算符,它通常与条件一起使用。
如果给定条件的结果为0,则not关键字返回1;如果给定条件的结果为1,则返回0。
语法:
not operand;
在这里,operand是操作数。
示例
Input:
a = 10;
b = 20;
result = not(a < b);
Output:
result = 1演示使用“not”关键字的C++示例
//C ++示例演示使用
//“非”运算符。
#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;
}输出:
false false true