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