在c语言中凡是未在调用前定义的函数,c语言编译程序都默认函数返回值为整形 解释解释这句

在c语言中凡是未在调用前定义的函数,c语言编译程序都默认函数返回值为整形 解释解释这句话 最好有一个例子 肯定好评

就是如果返回值类型如果不写的话,默认返回Int类数据。所以,自定义函数需要标注返回类型,否则得到的值不正确。
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <stdarg.h>
float sum(int a,int b,int m,...);
main (void)
{
int x=100;
int y=200;
int z=300;
int r=400;
float t=sum(x,y,z,r,0);
printf("the resulet is %f ,",t);
return 0;
}

float sum(int a, int b,int m,...)
{
va_list p;
int c=2;
float sun=a+b+m;
int i=0;
va_start(p,m);
while ((i=va_arg(p,int))!=0)
{
sun=sun+i;
c++;
}
return sun;
}

比如这个程序,你复制,然后编译,消除开始定义的 float ,结果完全不一样,你多试验,多改动几次返回值类型,你就明白了追问

为什么去掉后显示错误??

追答

因为开始不声明是float形势,那么就默认为是int,这个和后面的float冲突

第二个,有的编译器不会给错误警告,但是得不到正确的数值,我用的是dev c++

你逐渐改,你就知道你的提问是什么意思了

追问

unsigned [int] 占几个字节啊

还有这个 [ signed] int 占几个字节

追答

老版本的int是2个字节

现在都是四个,但是有的编译器不一样,可能有一些出入

你可以用sizeof(int) sizeof(unsigned int) 来确认

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-06-19
int main()

 atexit(MyExit);
 int k=test();
 return 0;

test(){
}

将鼠标放在test()上,VS 会提示你(缺少显示类型,默认“int")

将鼠标放在main()函数的test()上,会提示函数原型为 int test();