Fibonacci Function Question

前端 未结 8 1099
春和景丽
春和景丽 2020-12-31 21:22

I was calculating the Fibonacci sequence, and stumbled across this code, which I saw a lot:

    int Fibonacci (int x)
{
    if (x<=1) {
        return 1;
         


        
8条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-31 21:46

    Yes, the Fibonacci function is called again, this is called recursion.

    Just like you can call another function, you can call the same function again. Since function context is stacked, you can call the same function without disturbing the currently executed function.

    Note that recursion is hard since you might call the same function again infinitely and fill the call stack. This errors is called a "Stack Overflow" (here it is !)

提交回复
热议问题