通常,C中的所有函数参数都用逗号分隔,,
例如printf("Data",&a);
。
但是对于for
循环,参数用分号(for(i=0;i<5;++i)
)分隔,为什么会这样呢?
因为逗号是一个运算符,并且允许一个人做类似的事情
for (i=0,j=5; i<5; ++i, ++j)
PS:for
是关键字,不是上面指出的功能
**ISO/IEC 9899:1999 §6.8.5.3 The for statement** The statement for ( clause-1 ; expression-2 ; expression-3 ) statement behaves as follows: The expression expression-2 is the controlling expression that is evaluated before each execution of the loop body.
每次执行循环主体后,表达式expression-3都将被评估为void表达式。如果子句1是一个声明,则它声明的任何变量的范围是声明的其余部分和整个循环,包括其他两个表达式;它是在对控制表达式进行第一次评估之前按执行顺序达到的。如果子句1是一个表达式,则在对控制表达式进行第一次求值之前,它会被作为void表达式求值(133)
Both clause-1 and expression-3 can be omitted. An omitted expression-2 is replaced by a nonzero constant. 133) Thus, clause-1 specifies initialization for the loop, possibly declaring one or more variables for use in the loop; the
控制表达式expression-2指定在每次迭代之前进行的求值,以便继续执行循环,直到表达式比较等于0为止;表达式3指定在每次迭代之后执行的操作(例如递增)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句