# Thread: How Does Recursion Work?

1. ## How Does Recursion Work?

how does stack works when we called a variable storing recursion result  Reply With Quote

2. ## Re: How Does Recursion Work?

I am not sure but as my view, stack allocated every time in recrusion and stack size is repetitively increase. For your reference you can understand the exact meaning by the program :
Factorial with recursive and factorial with non recursive implementation  Reply With Quote

3. ## Re: How Does Recursion Work?

If we are using a recursive factorial function say FactA()

and put the result in a variable like

int I=FactA(5)

The FactA() will use stact to calculate the factorial and store it in I

and further in program we use the value of the variable then the value store in I Uses  Reply With Quote

4. ## Re: How Does Recursion Work?

Hi,
There are two methods recursive and non recursive : If you use stack in recursive method stack allocated every time in recrusion and stack size is repetitively increase. you its a not good practise,,,,,,, A simple example in performance perspective if you use recusive factorial program with more than 12 number then you should not use recusive method.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•