//逻辑运算符
//与(&&)或(||)非(!)
//作用:根据表达式的值返回真值或者假值
逻辑非
#include <iostream> using namespace std; int main() {
//在 C++ 中,除了 0 都是真 int a = 10; cout << !a << endl; cout << !!a << endl; system("pause"); return 0; }
逻辑与
#include <iostream> using namespace std; int main() {
//在 C++ 中,除了 0 都是真 //逻辑与 && 运算 int a = 10; int b = 10; cout << (a && b) << endl; int a1 = 10; int b1 = 0; cout << (a1 && b1) << endl; system("pause"); return 0; }
//两个都是真才为真,有一个假为假
逻辑或
#include <iostream> using namespace std; int main() {
//在 C++ 中,除了 0 都是真 //逻辑与 || 运算 //有一个为真则结果为真 int a = 10; int b = 0; cout<<(a || b) << endl; system("pause"); return 0; } //只要有一个为真,则表达式为真
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/233636.html原文链接:https://javaforall.net