我想调用“function2();”仅在第一次调用 recurfunc() 时单次。
recurfunc()
{
function2(); //to be called first time only in a recursive function
static int i= 0;
i++;
if(i>20)
return;
else
recurfunc();
}
最佳答案
对您的代码进行微不足道的更改:
void recurfunc() // * Remember to specify return type *
{
static int i= 0;
if (i==0)
function2(); // called only the first time.
i++;
if(i>20)
return;
else
recurfunc();
}
关于c - 如何仅在递归函数调用中第一次调用另一个函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15780212/