C#C
C#11mo ago
Faker

✅ How call stacks work in recursive calls

Hello guys, I've implemented a small funtion to find any nth term in the fibonnaci sequence.

C#
// Find nth term in fibonacci sequence - 0.1.1,...
Console.WriteLine(FibonacciFinder(5));
static int FibonacciFinder(int num)
{
    if (num is 1 or 2 or 3) return 1;
    else
    {
        return FibonacciFinder(num - 1) + FibonacciFinder(num - 2);
    }
}

I don't understand how the recursive calls work under the hood though. Like, I know that num-1 is called first, then when all its call stack is kind of "over" we move to the right hand side but this is still vague. I was wondering if there was kind of a visualization tool to see what's hapenning and what's being return for each call.
Was this page helpful?