这句话的用法是c99标准规定的,也就是说他可以在第一个控制表达式中声明循环变量,但是他的作用域是这个循环块内部,在外部不能被引用。
你可以用这样编译代码:gcc main.c -std=c89
main.c: In function ‘main’:
main.c:4: error: ‘for’ loop initial declarations are only allowed in C99 mode
main.c:4: note: use option -std=c99 or -std=gnu99 to compile your code
main.c
#include <stdio.h>
int main(void)
{
for (int count = 1; count <= 10; ++count)
printf("%d\t", count);
printf("we have finished\n");
return 0;
} 作者: keytounix 时间: 2011-11-18 10:42 回复 9#MMMIX