33,319
社区成员
发帖
与我相关
我的任务
分享#include <iostream>
using namespace std;
int fun(int n)
{
if (n == 1)
return 6;
else
fun(n - 1);
}
int main()
{
cout << fun(10);
}
#include <iostream>
using namespace std;
int fun(int n)
{
if (n == 1)
return 6;
else
return fun(n - 1);
}
int main()
{
cout << fun(10);
}
不应该是return fun(n1,s1);吗?[/quote]
但是你是func(n1, s1);并没有return func(n1, s1)呢。不要想当然哦,要看你的代码是否是这个逻辑。[/quote]
好吧 我再想想



不应该是return fun(n1,s1);吗?[/quote]
除了最后一个函数栈有返回,执行了return n-1;其他的都没执行,我上面已经说明的很清楚了。因为除了最后一个函数s1 >= 100之外,其他函数栈中s1 < 100;所以会继续执行func(n1, s1);但是func(n1, s1)后面没有代码可执行了,所以就退出函数栈了嘛
不应该是return fun(n1,s1);吗?[/quote]
但是你是func(n1, s1);并没有return func(n1, s1)呢。不要想当然哦,要看你的代码是否是这个逻辑。
不应该是return fun(n1,s1);吗?


