このコードを実行すると、出力は次のようになります。
hello5
hello4
hello3
hello2
hello1
0
1
2
3
4
それまでは理解してhello1
いますが、なぜ増加しているのかわかりません。誰かが私にこれを説明できますか?
#include <iostream>
#include <iomanip>
using namespace std;
void myFunction( int counter)
{
if(counter == 0)
return;
else
{
cout << "hello" << counter << endl;
myFunction(--counter);
cout << counter << endl;
return;
}
}
int main()
{
myFunction(5);
return 0;
}