求助
#include <stdio.h>int i = 520;
int func(void);
int func(void)
{
printf("%d, ", i);
int i = 880;
for (int i = 1; i < 3; i++)
{
printf("%d, ", i);
}
printf("%d\n", i);
}
int main(void)
{
func();
return 0;
}
这个是复制小甲鱼老师课后作业的代码,编译器报错了,请大神帮忙看看哪里出错了? 错误提示是什么? 人造人 发表于 2017-6-3 11:09
错误提示是什么?
--------------------Configuration: CC - Win32 Debug--------------------
Compiling...
CC.c
E:\新建文件夹\CC\CC.c(11) : error C2143: syntax error : missing ';' before 'type'
E:\新建文件夹\CC\CC.c(13) : error C2143: syntax error : missing ';' before 'type'
E:\新建文件夹\CC\CC.c(13) : error C2143: syntax error : missing ';' before 'type'
E:\新建文件夹\CC\CC.c(13) : error C2143: syntax error : missing ')' before 'type'
E:\新建文件夹\CC\CC.c(13) : error C2143: syntax error : missing ';' before 'type'
E:\新建文件夹\CC\CC.c(13) : warning C4552: '<' : operator has no effect; expected operator with side-effect
E:\新建文件夹\CC\CC.c(13) : error C2059: syntax error : ')'
E:\新建文件夹\CC\CC.c(14) : error C2143: syntax error : missing ';' before '{'
执行 cl.exe 时出错.
CC.obj - 1 error(s), 0 warning(s)
这个就是错误提示 微笑向暖~ 发表于 2017-6-3 16:25
--------------------Configuration: CC - Win32 Debug--------------------
Compiling...
CC.c
你使用什么编译器? 1)int i=880放在printf("%d, ", i);前面
2) for (int i = 1; i < 3; i++)改为 for ( i = 1; i < 3; i++)
3)int func(void)函数没有返回值或者设置为void类型
人造人 发表于 2017-6-3 16:34
你使用什么编译器?
vc++6.0 boom 发表于 2017-6-3 16:43
1)int i=880放在printf("%d, ", i);前面
2) for (int i = 1; i < 3; i++)改为 for ( i = 1; i < 3; i++) ...
这个是课后作业 局部变量和全局变量的一道题,这样一改,错误是没了,但是答案输出不一致了 微笑向暖~ 发表于 2017-6-3 17:00
vc++6.0
这段代码不能用vc6,vc6不支持c99标准 微笑向暖~ 发表于 2017-6-3 17:00
vc++6.0
VC6 只支持到 C90 标准,不支持随时随地定义变量……
页:
[1]