版权声明:本文为博主原创文章,未经允许不得转载 https://blog.csdn.net/noipBar/article/details/84592538
C++中一共有三个逻辑运算符:
1、逻辑与 && 运算符前后两个条件都为true才为true
2、逻辑或 || 运算符前后只要有一个条件为true就为true
3、逻辑非 ! 运算符后的表达式取反,非true为false,非false为true
逻辑运算符运用在条件语句和条件表达式中,以下是测试代码:
#include <iostream>
using namespace std;
int main()
{
int a=15,b=-10;
bool c,d,e;
c= ((a>0) && (b>0) && (c==true));
cout<<"c="<<c<<endl;
d = ((a>0) || (b>0));
cout<<"d="<<d<<endl;
e = !(a>0);
cout<<"e="<<e<<endl;
return 0;
}