【发布时间】:2011-10-12 01:15:12
【问题描述】:
考虑:
if (a=5) {
/* do something */
}
作业如何作为条件起作用?
是不是基于l-value的非零值?
【问题讨论】:
-
你是用 C++ 还是 C 编译?
-
int war = false; if(war = true) { launchnuke(); } -
@WTP:永远不要将布尔值与任何东西进行比较。布尔值已经是布尔值:
if (war) launchnuke();将true或false分配给非布尔值的程序员应该受到各种针对他们的攻击。 -
@David:WTP 在哪里比较布尔值和布尔值?
-
@Tomalak:他没有,但
if(var = true)可能打算成为if(var == true)。首先将其写为if (var)可以巧妙地避免潜在的=与==的混淆。
标签: c++ c if-statement assignment-operator evaluation