Hello ,
I have this code:
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
void message(int numbers)
{
cout << "Entry to function #" << numbers << endl;
if ( numbers > 0 )
{
cout << "This is a recursive function." << endl;
message( numbers-1 );
}
cout << "Exit from function #" << numbers << endl;
}
int main()
{
message(4);
return 0;
}
and the output is :
Entry to function #4
This is a recursive function.
Entry to function #3
This is a recursive function.
Entry to function #2
This is a recursive function.
Entry to function #1
This is a recursive function.
Entry to function #0
Exit from function #0
Exit from function #1
Exit from function #2
Exit from function #3
Exit from function #4
I would expect the : Exit from function
to be executed only one time, when the numbers
will be zero.
I can't understand how this is being executed ..When the numbers=0
, we have the Entry to funtion #0
and Exit from function #0.