帮忙啊

kevinxin24 2010-12-17 06:15:43
#include<stdio.h>
main()
{
int i;
for(i=0;i<=2;i++)
Plus();
}
Plus()
{
int a=0;
static int b=0;
printf("%d",a+b);
++a,++b;
}
要得到012的结果。请问哪儿错了,谢谢。
...全文
86 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
luckyyulin 2010-12-18
  • 打赏
  • 举报
回复
我也是刚开始学C语言,推荐看谭浩强的C语言程序设计,先掌握好基础,然后多编程序。
kevinxin24 2010-12-18
  • 打赏
  • 举报
回复
谢谢大家啊!我确实该多看看书,虽然是新手。
guoxijun 2010-12-17
  • 打赏
  • 举报
回复
答案都在楼上了,建议楼主补补基础
flysnowhite 2010-12-17
  • 打赏
  • 举报
回复
没错啊,就是少了个声明。将Plus函数定义放在main函数前面即可。
muyu1990 2010-12-17
  • 打赏
  • 举报
回复
[Quote=引用楼主 newstar1 的回复:]
#include<stdio.h>
main()
{
int i;
for(i=0;i<=2;i++)
Plus();
}
Plus()
{
int a=0;
static int b=0;
printf("%d",a+b);
++a,++b;
}
要得到012的结果。请问哪儿错了,谢谢。
[/Quote]


#include<stdio.h>
void main()
{
int i;
int Plus();
for(i=0;i<=2;i++)
Plus();
}
Plus()
{
int a=0;
static int b=0;
printf("%d",a+b);
++a,++b;
}
东门吹雪 2010-12-17
  • 打赏
  • 举报
回复
函数必须先声明,或者在main函数之前就定义。

#include<stdio.h>
void Plus(); //函数声明
void main()
{
int i;
for(i=0;i<=2;i++)
Plus();
}
void Plus()//函数定义
{
int a=0;
static int b=0;
printf("%d",a+b);
++a,++b;
}
浮一大白开水 2010-12-17
  • 打赏
  • 举报
回复
#include<stdio.h>
main()
{
int i;
for(i=0;i<=2;i++)
Plus();
}
Plus()
{
static int a=0;
static int b=0;
++a;
++b;
printf("%d",a+b);

}
a是局部变量
無_1024 2010-12-17
  • 打赏
  • 举报
回复

#include<stdio.h>
void Plus()
{
int a=0;
static int b=0;
printf("%d",a+b);
++a,++b;
}
main()
{
int i;
for(i=0;i<=2;i++)
Plus();
}


fc_cpp 2010-12-17
  • 打赏
  • 举报
回复
Plus函数调用前先声明 说明返回类型

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧