作用:用于根据表达式的值返回真值或假值
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
using namespace std;
int main()
{//逻辑运算符 非!int a = 10;int b = 20;//在c++中除了0都是真cout << !a << endl; //0cout << !!a << endl; //1//逻辑运算符 与&&a = 10;b = 10;cout << (a&&b) << endl; //1a = 0;b = 10;cout << (a && b) << endl; //0a = 0;b = 0;cout << (a && b) << endl; //0//逻辑运算符 或|| a = 0;b = 10;cout << (a && b) << endl; //1system("pause");return 0;
}
运行结果:
0
1
1
0
0
1
1
0
注:
与:同真为真,其余均为假
或:同假为假,其余均为真