Function output(#bbsr)

I am not able to understand how the output is coming like this. Can you help me out by a dry run.

HI @nayakashutosh99, what is this code for. like what is the question ?

It’s my doubt .
I don’t have question. I saw in a book and started trying it but my output was coming different. That’s why I asked.

According to me, the code will be implemented as follows :
line 14
line 7 : for value 3
( 3-1) = 2
line 7 : for value 2
(2-1)=1
line 7 : for value 1
(1-1)=0
since n is not >0 for this case, there will be returning from call stack, thus line 8 will be implemented thereafter
line 8 : cout <<“1”
line 9 : (1-1)=0

since again n is not >0 for this case, thus we have returning again, this time value will be 2
line 8 : cout <<“2”
line 9 : (2-1)=1
line 8 : cout<<“1”
line 9 : (1-1)=0;

now again n is not >0, for this case, we have returning again, this time value will be 3
line 8 : cout<<“3”
line 9 : (3-1)=2
(2-1)=1
(1-1)=0
cout<<“1”
cout<<“2”
then again for 2, we have (2-1)=1
thus cout<<“1”

try to understand through the above, if not i will send the flow of call stack…

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.