本文介绍了警告:控制到达非无效函数[-Wreturn-type]的末尾,即使带有"return 0;"也是如此.在主要功能上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这里有一些发出警告的代码

I have some code here that raises a warning

让我感到困惑的是,如果我在功能打印机中添加return 0;,警告将消失.我是C语言的新生,因此希望您能帮助我解决此问题.谢谢.

What makes me confused is that, if I add return 0; in function printer, the warning will disappear. I am a freshman to the language C, so hopefully you can help me solve this problem. Thanks.

#include <stdio.h>

int printer(int *ip){
    printf("%d", *ip);
//  return 0; //with the expression, the warning will disappear. why?
}

int main(int argc, char *argv[]){
    int number = 10;
    int *ip;
    ip = &number;

    printer(ip);
    return 0;
}

推荐答案

您声明打印机函数返回整数.

You declare the printer function to return an integer.

int printer(...

但是您不返回整数.我认为你需要做到

but you don't return an integer.I think you need to make it

void printer(...

为了使它在函数中没有return语句的情况下工作

in order for it to work without the return statement in the function

这篇关于警告:控制到达非无效函数[-Wreturn-type]的末尾,即使带有"return 0;"也是如此.在主要功能上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 12:12
查看更多