I was looking through my older notes from a class I took a few years ago, and it was saying the answer was 1 2 3 4 is what outputted when this is run. I would think it is 4 3 2 1, and I don't understand how it is the other way around. Would anyone be kind enough to explain what actually happens to make it 1 2 3 4? Thank you.

December 8th, 2013, 04:11 PM

andbin

Re: Question on how this works?

Quote:

Originally Posted by sammythesp3rmy

Would anyone be kind enough to explain what actually happens to make it 1 2 3 4? Thank you.

The print is after the recursive invocation of mystery. The last deepest invocation is with 0 but since there is the condition num>0, no recursion and no print happens. Then gets one step back, where the invocation was with 1 and print it ... and go back where was 2 .....