Dan*_*inu 6 c c++ expression operators
特定
int x=1,y=2,z;
Run Code Online (Sandbox Code Playgroud)
你能解释一下为什么结果:
x && y || z
Run Code Online (Sandbox Code Playgroud)
是1?
x && y = 1
x && y || z = 1
Run Code Online (Sandbox Code Playgroud)
Arm*_*yan 19
x && y || z
Run Code Online (Sandbox Code Playgroud)
相当于
(x && y) || z
Run Code Online (Sandbox Code Playgroud)
if x=1和y=2
then x&&y是1 && 2哪个是true && true哪个true.
true || z
Run Code Online (Sandbox Code Playgroud)
永远true.z甚至没有评估
(bool)1 = true
(bool)2 = true
Run Code Online (Sandbox Code Playgroud)
未初始化的int指的是保存在内存中的数据,它放在堆栈中......很少0x00000000,即使是,也是如此true || false = true.