有人请解释我原因
int i=0,j=10;
while(j>0,i++){
printf("%d%d",i,j);
j--;
}
Run Code Online (Sandbox Code Playgroud)
不会工作
int i=0,j=10;
while(i++,j>0){
printf("%d%d",i,j);
j--;
}
Run Code Online (Sandbox Code Playgroud)
作品.
还请告诉我原因
int i=0,j=10;
while(j>0,++i){
printf("%d%d",i,j);
j--;
}
Run Code Online (Sandbox Code Playgroud)
给出一个无限循环?
感谢致敬
戒
Vla*_*mir 16
在while循环条件中,使用逗号运算符,它会计算其参数并返回第二个参数.所以在你的例子中:
while(j>0,i++) - returns i before it gets incremented;
that is 0, so loop won't execute at all
while(i++,j>0) - returns (j > 0) - runs as expected
while(j>0,++i) - returns i - will run until i overflows max int value
Run Code Online (Sandbox Code Playgroud)