int factorial (int num) { if (num==1) return 1; return factorial(num-1)*num; // recursive call }

that's the code that I have although I'm not sure how it works.

My real problem with understanding this is ... well for example

if you're input is 5 (5! is 120) and it goes through the loop once it should get num=4 while 5*4 is 20 right? Well where the heck is 20 stored? It must be stored SOMEWHERE for it to be multiplied by 3 and then by 2 , correct?

So my question is how and why and where is the result (20,60,120) stored? There is only 1 variable and I'm pretty damn sure that 1 variable cannot store 2 pieces of data.

my friend told me the result is stored temporarily while it calculates but in no manner does my code ever tell the computer that there is a RESULT variable which stores the result.

how can it keep track of the multiplied number AND the current num value? that is confusing to me. Maybe I don't understand the process of recursion or something but tell me if i'm wrong

if num=5

then num=4

then num=3

then num=2

then num=1

then which variable is left to spit out 120?

I'm so confused and frustrated.

Just to state what I'm trying to say one more time and more clearly:

My idea of this function is that it stores 5 in num. Then turns 5 to 4 so it forgot about 5 already. and then it says *num. so what the heck happens? Or does it still remember 5?

Please show me the logic !!!! I have lost all faith in computing at the moment. If there is no logic in this I'll be in deep depression for a year