将常量和变量与左边的常量进行比较有什么好处


What is the benefit of comparing constant and variable with constant on the left?

有人能解释将常数和变量与左边的常数进行比较的好处吗?例如

if (0 == variable)

代替

if (variable == 0)

如果你说

if (variable == 0)

你有遗漏一个=并说的风险

if (variable = 0)

其将变量CCD_ 2设置为CCD_。

因此,将0放在左边可以更安全地输入错误,因为0 = variable将无法为变量设置任何值。