qfedu-basic-level/day6/d4.cpp

13 lines
279 B
C++

// 逻辑或短路
#include <iostream>
using namespace std;
int main()
{
int a = 4, b = 2;
a += b; // a = 6
a = (a >= b) || b++; // 6 >= 2 =>1 || b++ 右侧的b++不会执行
cout << a << "," << b << endl; // 1,2
return 0;
}