Arm*_*yan 19

x && y || z 
Run Code Online (Sandbox Code Playgroud)

相当于

(x && y) || z
Run Code Online (Sandbox Code Playgroud)

if x=1y=2 then x&&y1 && 2哪个是true && true哪个true.

true || z 
Run Code Online (Sandbox Code Playgroud)

永远true.z甚至没有评估


Pau*_*aul 6

x && y || z=> (x && y) || z=> 1 || z=>1


Gri*_*wes 5

(bool)1 = true
(bool)2 = true
Run Code Online (Sandbox Code Playgroud)

未初始化的int指的是保存在内存中的数据,它放在堆栈中......很少0x00000000,即使是,也是如此true || false = true.


wil*_*ilx 5

&&经营者具有比更高的优先级||运营商.参见,例如,此运算符优先级表,数字13和14.

您的示例评估为(x && y) || z.由于短路规则,z从未评估过,因为结果x && y已经存在true.