When I excuted this belo program, it is printing 5
inifnitely. Why?
Is it because the decrement is not happening or before decrement happens function call is happening?
I have tried the alternate way making fun(--n)
, it gave me correct answer. But why it is not working for fun(n--)
?
void fun(int n)
{
if(!n)
{
cout << n << " " << endl;
}
else
{
cout << n << " "<<endl;
fun(n--);
}
}
int main()
{
int n = 5;
fun(n);
system("pause");
return 0;
}