原帖由 goodhermit95 于 2009-10-28 09:27 PM 发表 
前面为什么要int i?
因为要 declare variable 啊em0051
我在 for loop 外面 declare 的原因是我用的 cl.exe 不支持 ANSI C99 Standard.
- #include <stdio.h>
- int main()
- {
- for (int i = 1; i <= 100; i++)
- i % 10 == 0 ? printf("\n") : printf("*");
- return 0;
- }
复制代码
- C:\Users\Dhilip89\Desktop>cl star.c
- Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
- Copyright (C) Microsoft Corporation. All rights reserved.
- star.c
- star.c(6) : error C2065: 'i' : undeclared identifier
- star.c(6) : error C2065: 'i' : undeclared identifier
- star.c(6) : error C2065: 'i' : undeclared identifier
- star.c(7) : error C2065: 'i' : undeclared identifier
- C:\Users\Dhilip89\Desktop>cl star.c
- Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
- Copyright (C) Microsoft Corporation. All rights reserved.
- star.c
- star.c(6) : error C2065: 'i' : undeclared identifier
- star.c(6) : error C2065: 'i' : undeclared identifier
- star.c(6) : error C2065: 'i' : undeclared identifier
- star.c(7) : error C2065: 'i' : undeclared identifier
复制代码
- #include <stdio.h>
- int main()
- {
- int i;
- for (i = 1; i <= 100; i++)
- i % 10 == 0 ? printf("\n") : printf("*");
- return 0;
- }
复制代码- C:\Users\Dhilip89\Desktop>cl star.c
- Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
- Copyright (C) Microsoft Corporation. All rights reserved.
- star.c
- Microsoft (R) Incremental Linker Version 9.00.30729.01
- Copyright (C) Microsoft Corporation. All rights reserved.
- /out:star.exe
- star.obj
- C:\Users\Dhilip89\Desktop>star
- *********
- *********
- *********
- *********
- *********
- *********
- *********
- *********
- *********
- *********
复制代码