Recursion -Fibonacci number

While analyzing the Fibonacci using recursion using the code:
#include
using namespace std;
int fib(int n){
if(n==0||n==1)
return n;
int f1 = fib(n-1);
cout<<n<<endl;
int f2 = fib(n-2);
cout<<n<<endl;
return f1+f2;
}
int main(){
int n;
cin>>n;
int ans;
ans = fib(n);
cout<<"ANS: "<<ans;
I get the following output but I am confused that how this last 4 line before ANS(4 2 2 4) will come.
OUTPUT:
4
2
2
3
3
4
2
2
4
3

Please save your code on ide.codingblocks.com and then share its link.

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.