首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

哪位高手能告诉小弟我一个函数里两次或多次递归时,堆栈的调用过程吗

2012-05-20 
谁能告诉我一个函数里两次或多次递归时,堆栈的调用过程吗?#include iostreamusing namespace stdvoid d

谁能告诉我一个函数里两次或多次递归时,堆栈的调用过程吗?
#include <iostream>
  using namespace std;

  void dosomething(int);
  int _tmain(int argc, _TCHAR* argv[])
 {

  int value=5;
  dosomething(value);
  system("pause");
return 0;
 }
  void dosomething(int a)
 {
  a-=1;

  if(a>0)
  {
  dosomething(a);
  dosomething(a);
  }

  cout<<"a:"<<a<<endl;
 }

[解决办法]

C/C++ code
#include <iostream>  using namespace std;  void dosomething(int);  int main(int argc, char* argv[]) {  int value=5;  dosomething(value);  return 0; }  void dosomething(int a) {  a-=1;  if(a>0)  {    cout<<"fn1-----------";  dosomething(a);   cout<<"fn2======";  dosomething(a);  }  cout<<"a:"<<a<<endl; } 

热点排行