if ((vnd = (struct diam_vnd_t *)g_hash_table_lookup(vendors,vend))) {...}
你能告诉我为什么它是赋值而不是括号中的 boolean 表达式吗?在什么情况下这个赋值可以被认为是“真”或“假”?
最佳答案
引用 C11
,第 6.5.16 章,赋值运算符(强调我的)
An assignment operator stores a value in the object designated by the left operand. An assignment expression has the value of the left operand after the assignment,111) but is not an lvalue.
因此,首先会发生赋值,然后,已赋值的值将用作if
中的条件语句。
所以,如果是
if (p = 0 )
将评估为 FALSE 并且
if (p = 5)
将为真。
关于c - if 语句中的赋值语句如何充当条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37166250/