【发布时间】:2013-07-29 13:18:23
【问题描述】:
我想知道这个程序是如何执行的并且没有抛出任何错误。
void main( )
{
clrscr();
int i ;
for ( i = 1 ; i <= 5 ; printf ( "\n%c", 65 ) ) ;
i++ ;
getch();
}
循环继续打印 A 永远。 for循环的格式是
for(initialize value; test counter; increment value)
{
do this;
and this;
and this;
}
我的问题是 printf("\n %c", 65) 如何增加值?
【问题讨论】:
-
i++无法访问。 -
printf成功返回写入的字符总数。它没有增加i -
谁给了你这个棘手的代码?
-
为什么要让你的生活复杂化?删除
;后,将i++放在应有的位置。不要做奇怪的事情,没有人会爱你。 -
分号被视为循环体。根据
(C99, 6.8.3p3) "A null statement (consisting of just a semicolon) performs no operations."