对一个递归调用的例子不理解,请大家帮忙.
nnh 2006-08-07 10:05:50 // recur.cpp -- use recursion
#include <iostream>
void countdown(int n);
int main()
{
countdown(4); // call the recursive function
system("pause");
return 0;
}
void countdown(int n)
{
using namespace std;
cout << "Counting down ... " << n << endl;
if (n > 0)
countdown(n-1); // function calls itself
cout << n << ": Kaboom!\n";
}
我对于代码最后也输出:
1: Kaboom!
2: Kaboom!
3: Kaboom!
4: Kaboom!
不是很理解,请大家帮忙解释一下,谢谢