Return in function

please explain more about example based on return statement,how does it work when we use like return A+fact(A-1)

@mkjha hi manish, i am unable to understand your doubt, could you please elaborate a bit?

https://ide.codingblocks.com/s/180350 please visit and more explain about function part,how does it work line by line.

line 11 sends the flow of control to line 3, where a = 5
Now condition at line 5 fails, so we go to line 8 and return a + sum(a - 1), ie
5 + sum(4). Remember that this value will be returned to our main function and ultimately printed. Let us remember this call to sum() function as call5 for our convenience.
since sum() function is called again, we have to determine its value for a = 4. Let us remember this call to sum() function as call4 for our convenience.
if condition fails again and so we return 4 + sum(3).
now sum() is called again for a = 3. Let us remember this call to sum() function as call3 for our convenience.
it will return 3 + a(2)
now sum() is called again for a = 2. Let us remember this call to sum() function as call2 for our convenience.
it will return 2+ a(1)
now sum() is called again for a = 1. Let us remember this call to sum() function as call1 for our convenience.
it will return 1 + a(0)
Now sum() is called for a = 0
condition at line 5 is satisfied, so the function returns a, ie 0.
now the flow of control goes back to call1. Its going to return 1 + a(0) and a(0) returned us the value 0. Therefore call1 will return 1 + 0, ie 1
now the flow of control goes back to call2. Its going to return 2 + a(1) and a(1) returned us the value 1. Therefore call2 will return 2 + 1, ie 3
now the flow of control goes back to call3. Its going to return 3 + a(2) and a(2) returned us the value 3. Therefore call3 will return 3 + 3, ie 6
now the flow of control goes back to call4. Its going to return 4 + a(3) and a(3) returned us the value 6. Therefore call4 will return 4 + 6, ie 10
now the flow of control goes back to call5. Its going to return 5 + a(4) and a(4) returned us the value 10. Therefore call5 will return 5 + 10, ie 15
now the flow of control goes back to the main() function and the value 15 is printed on the screen.

@mkjha i hope i have resolved your doubt now. If you are satisfied please mark your doubt as resolved. You can always reopen it if any further queries arise.

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.