+ 9
Can someone explain me this code ???
It is an example of recursive function from learncpp.com . I can't understand why the output includes this: pop 2 pop 3 pop 4 pop 5 Website link: http://www.learncpp.com/cpp-tutorial/7-11-recursion/
6 Answers
+ 6
Is there a reason why you wouldn't expect these to output, considering there is a line printing these to the output stream?
What behavior were you expecting with the pop messages?
Remember, each recursive call will [first] execute everything above the recursive call line. After the final recursive call is completed, execution will proceed below the recursion line for each call on the stack.
[UPDATED: Added word in bracket for clarity.]
+ 9
@David
"After the final recursive call is completed, execution will proceed below the recursion line for each call on the stack."
Ok I understood it . Thanks!!!
This is a property of every recursive function right ?
+ 7
@Junaid... As this code was written, that is the behavior. If you were attempting a different behavior, let me know and I can help with what needs to be modified.
+ 6
@David
I was expecting this output:
First all push statements
pop 1
Just this.
But I think I understood it now properly.
Watched some videos on YouTube.
Thanks for helping brother!!đ
+ 6
Gotcha... I'm glad I could help.
+ 1
one time return 1,