[英]Does while loop have two Arguments?
夫人给我一个问题要解决。 预测以下代码的输出。
#include <stdio.h>
int main()
{
int i = 0, j = 0;
printf("Output is : ");
while (i < 5, j < 10) // Doubt: how does while accept 2 arguments?? and how it works??
{
i++;
j++;
}
printf("%d, %d\n", i, j);
}
我认为这是语法错误。 但是当我尝试跑步时,它给了我输出。
Output is : 10, 10
但是如何? 谁能解释?
但是,如果我删除第一个printf语句, printf("Output is : ");
并运行它,我的防病毒软件会向我发出检测到Trojan
的警报。 但是它如何成为Trojan
?
逗号运算符是二进制运算符,它求值第一个操作数并丢弃结果,然后求值第二个操作数并返回此值。
所以就你而言
First it will increment i and j upto 5 and discard.
Second it will iterate i and i upto 10 and provide you the result as 10, 10.
您可以使用以下代码进行确认,
while (i < 5, j < 10) // Doubt: how does while accept 2 arguments?? and how it works??
{
i++;
j+ = 2;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.