小编Joh*_*nor的帖子

为什么计数器递增?

当我运行此代码时输出为:

hello5
hello4
hello3
hello2
hello1
0
1
2
3
4
Run Code Online (Sandbox Code Playgroud)

我明白了,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;
}
Run Code Online (Sandbox Code Playgroud)

c++ recursion

2
推荐指数
1
解决办法
123
查看次数

标签 统计

c++ ×1

recursion ×1