I'm beginner in recursion and I did this code
#include <stdio.h>
int ft_recursive_factorial(int nb)
{
if (nb > 1)
{
return(nb * ft_recursive_factorial(nb - 1));
}
return(1);
}
int main()
{
printf("%d\n",ft_recursive_factorial(3));
return(0);
}
Output
6
I think the code is correct but i can't understand what happen in the stack... In my mind this happening:
| Stack |
| return(1 * ft_recursive_factorial(1 - 1)) |
| return(2 * ft_recursive_factorial(2 - 1)) |
| return(3 * ft_recursive_factorial(3 - 1)) |
In this schema the code would be stop at return(1 * ft_recursive_factorial(1 - 1))
because of the return answer (in my mind).
Can someone explain me what happening in the stack ? please.