Hello everyone, I need help in understanding the recursion on how does it end in 12345678910. When I tried to understand this problem, I expected that the output should be 10987654321. How does the problem end up in 12345678910? I'm having difficulties in learning the logical flow of recursion.
#include <iostream>
using namespace std;
void recursion (int number) {
if (number == 0)
return;
recursion (number-1);
cout << number;
}
int main()
{
recursion(10);
return 0;
}
Yeah, but I just need more information on it because I'm still having difficulties in dealing with it. I'm having a hard time in understanding it mentally.
yes, recursion gives you a 'free' stack data structure effectively.
the call stack is absolutely critical to debugging large programs, and your IDE/debugger will provide it to you on demand when debugging. Ironically its hard to follow during recursions, but its mighty helpful when you end up in function foo () with a nullptr or nan or other unexpected value and want to know "where did THAT come from".