#include <stdio.h>
main()
{
int x = 1, y = 0, z = 5;
int a = x && y || z++;
printf("%d", z);
}
此代碼給我輸出:6C編程增量邏輯錯誤
#include <stdio.h>
main()
{
int x = 1, y = 0, z = 5;
int a = x && y && z++;
printf("%d", z);
}
此代碼給我輸出:5
爲什麼第二程序給出輸出中爲5即使z爲遞增相同像第一個程序一樣?
「||」和「|」之間的區別 與上面相同,在「||」的情況下,只執行一個語句,如果返回「true」,則其他語句不會執行。但是,如果第一個是錯誤的,那麼將檢查其他值是否爲「真」。原因是「或」運營商的工作方式。 「或」運算符僅依賴於一個真實的,換句話說,如果任何表達式都爲真,那麼結果將爲真。 –
https://www.codeproject.com/Articles/662248/Difference-between-and-and –