我无法理解此 C 代码如何在执行时产生堆栈溢出?执行步骤是什么?请帮忙。
#include <stdio.h>
int main() //Main function
{
reverse(1);
}
void reverse(int i) //Reverse function
{
if (i > 5)
exit(0);
printf("%d\n", i);
return reverse(i++);
}
最佳答案
您的函数以 1 为参数递归调用,直到堆栈上没有更多空间为止。
我认为您想使用 ++i
而不是 i++
。
关于c - 此 C 代码如何在执行时产生堆栈溢出?执行步骤是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43982309/