From 1a98dde7d59d5ac73a40b469187ace0ae2fbb85e Mon Sep 17 00:00:00 2001 From: flykhan Date: Mon, 19 Jun 2023 15:08:08 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=BB=E8=BE=91=E8=BF=90=E7=AE=97=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day6/d3.cpp | 14 ++++++++++++++ day6/d4.cpp | 13 +++++++++++++ day6/d5.cpp | 12 ++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 day6/d3.cpp create mode 100644 day6/d4.cpp create mode 100644 day6/d5.cpp diff --git a/day6/d3.cpp b/day6/d3.cpp new file mode 100644 index 0000000..adfcb43 --- /dev/null +++ b/day6/d3.cpp @@ -0,0 +1,14 @@ +// 逻辑与短路 +#include +#include + +using namespace std; + +int main() +{ + int a = 3, b = 4; + int c = (a 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 +} diff --git a/day6/d4.cpp b/day6/d4.cpp new file mode 100644 index 0000000..1968592 --- /dev/null +++ b/day6/d4.cpp @@ -0,0 +1,13 @@ +// 逻辑或短路 +#include + +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; +} \ No newline at end of file diff --git a/day6/d5.cpp b/day6/d5.cpp new file mode 100644 index 0000000..bea31c3 --- /dev/null +++ b/day6/d5.cpp @@ -0,0 +1,12 @@ +// 逻辑非测试 +#include + +using namespace std; + +int main() +{ + int a, b; + cin >> a >> b; // 3 4 + cout << "!(a > b) = " << !(a > b) << endl; // !0 = 1 + return 0; +} \ No newline at end of file