我试图预测这个程序的输出:
#include
void fun(int x)
{
if (x > 0)
{
fun(--x);
printf("%d\t", x);
fun(--x);
}
}
int main()
{
int a = 4;
fun(a);
getchar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
该程序的输出是:
0 1 2 0 3 0 1
Run Code Online (Sandbox Code Playgroud)
我知道很难用术语来解释,但我想知道的是当4作为参数传递而不是第一个语句fun(4--)即fun(3)执行时,所以从这里做一个调用fun(3)或者3打印然后fun(3--)语句被执行,因为基本上我是对以下顺序感到困惑:
fun(--x);
printf("%d\t", x);
fun(--x);
Run Code Online (Sandbox Code Playgroud)
执行这3个语句.