#include<iostream>
usingnamespace std;
int recursion(int x);
int main()
{
int x=1;
cout<<"The number in the main : "<<recursion(x)<<endl;
}
int recursion(int x)
{
if(x == 9) return 9;
recursion(x+1);
cout<<"The number you entered is : "<<x<<endl; // how did this get printed out when theres a recursive function before it
}
and also why does the return value of my base case which is 9 , is not 9 when i printed it out in my main function
well, I can answer the last bit. The reason you're outputting some weird number in main, is because you are failing to provide a return value when x != 9.
also, it only recurses until x == 9. at which point the 9th instance returns, and proceedes with the line following the function call in the 8th instance, which is the first cout << "the number you entered... " After which that call returns to the 7th instance which does the same. then the 6th.