A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

本帖最后由 木冉 于 2015-11-14 11:13 编辑

今天练习敲代码的时候遇到的问题,请大神帮忙解惑,谢谢~

  1. /*函数调用
  2. 1)无参无返回值函数
  3. 2)无参有返回值函数
  4. 3)有参无返回值函数
  5. 4)又参有返回值函数
  6. */

  7. #include <stdio.h>
复制代码
因为刚开始,用的是Microsoft visual c++编的代码,提示以下错误:D:\代码\06\函数调用.c(42) : error C2143: syntax error : missing ';' before 'type'
D:\代码\06\函数调用.c(42) : error C2143: syntax error : missing ';' before 'type'
D:\代码\06\函数调用.c(42) : error C2143: syntax error : missing ')' before 'type'
D:\代码\06\函数调用.c(42) : error C2143: syntax error : missing ';' before 'type'
D:\代码\06\函数调用.c(42) : error C2065: 'i' : undeclared identifier
D:\代码\06\函数调用.c(42) : warning C4552: '<' : operator has no effect; expected operator with side-effect
D:\代码\06\函数调用.c(42) : error C2059: syntax error : ')'
D:\代码\06\函数调用.c(43) : error C2146: syntax error : missing ';' before identifier 'printf'
执行 cl.exe 时出错.

函数调用.obj - 1 error(s), 0 warning(s)

经过好几次试验发现,当把for循环定义的int i去掉,在for外面定义int i;就不报错了,请各位帮忙解释一下这是为什么,谢谢


12 个回复

倒序浏览
代码没发全,看不到
回复 使用道具 举报
Marlong 发表于 2015-11-10 11:43
代码没发全,看不到
  1. #include <stdio.h>
  2. int main(){
  3.         void print_line(int n);
  4.         print_line(5);
  5.         return 0;
  6. }
  7. //有参无返回值
  8. void print_line(int n){
  9.         for (int i=0;i<n;i++)
  10.         printf("------------\n");       
  11. }
复制代码
不知到为啥没发全,不好意思
回复 使用道具 举报
VC上编译了之后没有报错,应该是你之前程序格式没写对,编译后老提示你少了分号,少了右括号

回复 使用道具 举报
Marlong 发表于 2015-11-10 12:37
VC上编译了之后没有报错,应该是你之前程序格式没写对,编译后老提示你少了分号,少了右括号

...

我的一直在报错,,删删减减的改了好几遍,还是那样,但是如果在for外面定义int i的话就不会报错
回复 使用道具 举报
可能是编译器的问题,我用的c.free也遇到过同样问题
回复 使用道具 举报
cube川 中级黑马 2015-11-11 18:34:35
7#
没问题吧
回复 使用道具 举报
木冉 中级黑马 2015-11-11 22:23:03
8#
叶良辰 发表于 2015-11-10 13:43
可能是编译器的问题,我用的c.free也遇到过同样问题

恩,有可能,谢谢`
回复 使用道具 举报
木冉 中级黑马 2015-11-11 22:24:14
9#

就是报错,,哎
回复 使用道具 举报
木冉 发表于 2015-11-11 22:24
就是报错,,哎

我用VS编C也经常出错,但是检查的时候并没有问题。
回复 使用道具 举报
应该是你的编译器问题,我用xcode没报错
回复 使用道具 举报
木冉 中级黑马 2015-11-12 15:15:02
12#
触底反弹 发表于 2015-11-12 11:01
应该是你的编译器问题,我用xcode没报错

好的,谢谢~
回复 使用道具 举报
chensc 金牌黑马 2015-11-12 20:29:39
13#
学习学习!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马