gpt4 book ai didi

c - "control reaches end of non-void function"是什么意思?

转载 作者:太空狗 更新时间:2023-10-29 16:27:36 24 4
gpt4 key购买 nike

我在这个二进制搜索算法上遇到了奇怪的编译器错误。我收到一条警告,提示 control reaches end of non-void function。这是什么意思?

int binary(int val, int sorted[], int low, int high) {
int mid = (low+high)/2;

if(high < low)
return -1;

if(val < sorted[mid])
return binary(val, sorted, low, mid-1);

else if(val > sorted[mid])
return binary(val, sorted, mid+1, high);

else if(val == sorted[mid])
return mid;
}

最佳答案

编译器无法从该代码判断函数是否会到达末尾并仍然返回一些东西。为清楚起见,将最后一个 else if(...) 替换为 else

关于c - "control reaches end of non-void function"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6171500/

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