i have a function called fun1(), which is used for recursion. I am confused regarding the first call to this fun(--n);. What it will do and how will my stack pop my functions after each function finishes?
void fun(int n)
{
if(n>0)
{
fun(--n);
printf("%d",n);
fun(--n);
}
}
My main function is as below:
int a;
a=3;
fun(a);
I want to know the order of execution and what my stack will contain before, during, and after the function call of the first fun(--n).
Your output will be 0, then 1, then 2, and then 0.
What you aren’t seeing is the intermediate calls. This is the full output (before the n > 0 part):