得到一个“返回类型默认为 'int' "当我在 int main() 之前声明 Shortf 函数时发出警告.为什么? [英] Getting a " return type defaults to 'int' " warning when I declare Shortf function before int main(). Why?

查看:56
本文介绍了得到一个“返回类型默认为 'int' "当我在 int main() 之前声明 Shortf 函数时发出警告.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <stdio.h>
int w=7,v=0;
shortf(short a, short *b)
{
    a++;(*b)++;w++;v++;
    printf("13: %d %d %d",a,v,w); return a;
}
int main()
{
    return 0;
}

这是我的代码的一部分.它是我大学的一位老师给我的,但是当我写它时,我收到了 10 多个警告和错误,这就是其中之一.我在第 4 行收到返回类型默认为 'int'"警告.为什么?注意:我只允许使用 C.

This is part of my code. It was given to me by a teacher in my University, but when I write it I get 10+ warnings and errors, this is one of them. I get a " return type defaults to 'int' " warning for Line 4. Why? Note: I am only allowed to use C.

推荐答案

您没有为函数 shortf 声明返回类型.因此编译器警告您将使用 int 的默认类型.

You did not declare a return type for the function shortf. And so the compiler warned you that the default type of int will be used.

您应该始终声明返回值类型.我的猜测是代码刚刚被错误地转录.我觉得应该是:

You should always declare a return value type. My guess is that the code has just been transcribed incorrectly. I think it should be:

short f(short a, short *b)

这篇关于得到一个“返回类型默认为 'int' &quot;当我在 int main() 之前声明 Shortf 函数时发出警告.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆