for(a=1,b=1,c=1;a<3,b<4,c<5;a++,b++,c++)

来源:百度知道 编辑:UC知道 时间:2024/09/20 03:47:15
这样的for循环可以吗?

可以for(int a=1,b=1,c=1;a<3,b<4,c<5;a++,b++,c++)

可以,直到c不小于5

这空循环没啥用啊

The comma operator has left-to-right associativity. Two expressions separated by a comma are evaluated left to right. The left operand is always evaluated, and all side effects are completed before the right operand is evaluated.

Commas can be used as separators in some contexts, such as function argument lists. Do not confuse the use of the comma as a separator with its use as an operator; the two uses are completely different.

Consider the expression

e1 , e2

The type and value of the expression are the type and value of e2; the result of evaluating e1 is discarded. The result is an l-value if the right operand is an l-value.

逗号表达式的值是最右边子表达式的值 ,这样的循环可以 ,但条件判断部分的前两条判断语句并不起作用 ,这或许不是你的本意。改成 while 循环吧 ,如果在循环内修改或使用 a,b,c 的值的话逻辑会更清晰一些

当然可以..条件,增量,初始值都有..没问题

可以,但不要这样写!