¥¥¥C与C++函数表达问题¥¥¥

wfy 2003-07-31 02:29:36
从C升级到C++,学到函数时,以下CODE在C中通过在C++通不过,请教为什么?C与C++在函数调用的书写有什么不同?
#include <iostream.h>
void fac();
void main()
{
int n;
float s;
cin >> n;
s=fac(int n); /编译提示在此出错,为什么?C确可以通过/
cout << s;
}

float fac(int x)
{
int f;
if(x==0||x==1) f=1;
else f=fac(x-1)*x;
return f;
}
...全文
37 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wwj886 2003-07-31
  • 打赏
  • 举报
回复
#include <iostream.h>

float fac(int x)
{
int f;
if(x==0||x==1) f=1;
else f=fac(x-1)*x;
return f;
}

void main()
{
int n;
float s;
cin >> n;
s=fac(n); //行不行?
cout << s;
tanck 2003-07-31
  • 打赏
  • 举报
回复
函数的声明和定义不一致
Bandry 2003-07-31
  • 打赏
  • 举报
回复
#include <iostream.h>

float fac(int x)
{
int f;
if(x==0||x==1) f=1;
else f=fac(x-1)*x;
return f;
}

void main()
{
int n;
float s;
cin >> n;
s=fac(int n); /编译提示在此出错,为什么?C确可以通过/
cout << s;
}
oceancat 2003-07-31
  • 打赏
  • 举报
回复
你的代码太混乱了,
前面的声名是void fac();
后面的实现是float fac(int x)
这个怎么会通过
肯定是报函数没有参数错误
jp311 2003-07-31
  • 打赏
  • 举报
回复
C的void fac() 等价于 C++的void fac(...)
C++的void fac() 等价于 C的void fac(void)
jyfcsdn 2003-07-31
  • 打赏
  • 举报
回复
#include <iostream.h>
void fac(); //这句应该改为float fac(int x);
wfy 2003-07-31
  • 打赏
  • 举报
回复
问题没有解决
系统提示:Expression syntax
极速小王子 2003-07-31
  • 打赏
  • 举报
回复

s=(float)fac(int n); //看看如何?
oayaya 2003-07-31
  • 打赏
  • 举报
回复
把错误提示一起贴出来啊..

65,208

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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