在这个特定的代码中,我无法看到它是如何输出的1.控件到达函数返回int类型的末尾而不会遇到return语句,因此不应该有运行时错误.我尝试将其他一些值传递给函数,所有都打印相同的值,1因为b之前结果是奇数0.
我试着搜索int返回函数的默认返回值,但无法得到满意的答案.有人说,默认的返回值是0,那么为什么1是这里的输出?
int fun(int a, int b) {
if (b == 0) {
return 0;
}
if (b % 2 == 0) {
return fun(a + a, b / 2);
}
}
int main() {
printf("%d", fun(6, 3));
return 0;
}
Run Code Online (Sandbox Code Playgroud)