[英]comma separated arguments in if statement condition
Whats the significance of first argument in an if
statement if it's just going to be ignored? 如果它只是被忽略,
if
语句中第一个参数的意义是什么? For instance, in: 例如,在:
#include<stdio.h>
main()
{
if(1,0)
printf("abc");
else
printf("qwe");
}
That's not an argument list, it's the comma operator. 这不是一个参数列表,它是逗号运算符。
If you have a statement like foo(), bar()
, then foo()
will be called and its result discarded, then bar()
will be called and the entire statement's result will be bar()
's result. 如果你有一个像
foo(), bar()
这样的语句,那么将调用foo()
并丢弃它的结果,然后调用bar()
并且整个语句的结果将是bar()
的结果。 Something like if(foo(),bar())
might be used if calling foo()
has some side effect that needs to happen for some reason. 如果调用
foo()
有一些副作用需要由于某种原因发生,可能会使用if(foo(),bar())
类的东西。
For something like 1,0
, that is exactly the same as just saying 0
and there is no significance to the 1
. 对于类似于
1,0
东西,这与仅仅说0
相同,并且对1
没有意义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.