qfedu-basic-level/day6/d3.cpp

15 lines
331 B
C++
Raw Permalink Normal View History

2023-06-19 15:08:08 +08:00
// 逻辑与短路
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
int a = 3, b = 4;
int c = (a<b) && (--a); // a自减1, a = a-1 => a = 2, c = 1
int d = (a>b) && (a++); // a++不会执行 => a = 2, d = 0
cout << a << "," << b << endl; // 2, 4
cout << c << "," << d << endl; // 1, 0
}