gpt4 book ai didi

c - 警告 : control reaches end of non-void function [-Wreturn-type] even if with "return 0;" in main function

转载 作者:行者123 更新时间:2023-11-30 21:14:43 25 4
gpt4 key购买 nike

我这里有一些代码会引发警告

control reaches end of non-void function [-Wreturn-type].

让我困惑的是,如果我在函数打印机中添加return 0;,警告就会消失。我是C语言的新手,所以希望你能帮我解决这个问题。谢谢。

#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;
}

最佳答案

您声明打印机函数返回一个整数。

int printer(...

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

void printer(...

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

关于c - 警告 : control reaches end of non-void function [-Wreturn-type] even if with "return 0;" in main function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42604016/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com