返回信息流#include<stdio.h>
int main()
{
prtstr(2, 4);
}
void prtstr(int a)
{
printf("%d\n", a);
printf("hello world\n");
}
上面的程序编译为什么只有警告不出错?
#include<stdio.h>
void prtstr();
int main()
{
prtstr(2, 4);
}
void prtstr(int a)
{
printf("%d\n", a);
printf("hello world\n");
}
然后加了void prtstr();声明后编译直接通过?
#include<stdio.h>
void prtstr(int a);
int main()
{
prtstr(2, 4);
}
void prtstr(int a)
{
printf("%d\n", a);
printf("hello world\n");
}
然后加void prtstr(int a)声明又出错了?实在是糊涂了,求解答!
这是一条镜像帖。来源:北邮人论坛 / cpp / #85555同步于 2015/1/31
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
[问题]gcc编译的问题
glifeng0
2015/1/31镜像同步4 回复
订阅后,新回复会通过你的通知中心匿名送达。
4 条回复
删了
【 在 glifeng0 的大作中提到: 】
: [code=c]
: #include<stdio.h>
: int main()
: ...................
C语言中使用prtstr()代表可以有任意多个参数,C++中则是标示没有参数。(多么奇葩的一个区别)[ema10]
所以第二个是没有问题的。
声明了prtstr(int a)之后,代表只有一个参数,使用时两个参数是错误的。
第三个是错的
好吧,原来有这种区别。谢谢!
【 在 betatheta 的大作中提到: 】
: C语言中使用prtstr()代表可以有任意多个参数,C++中则是标示没有参数。(多么奇葩的一个区别)
: 所以第二个是没有问题的。
: 声明了prtstr(int a)之后,代表只有一个参数,使用时两个参数是错误的。
: ...................