嗨有人可以解释这段代码吗?了解递归和递减
#include <stdio.h>
int main(){
void myfunc(int x){
printf (" [%d]",x);
printf ("M here 1\n");
if (x > 0) myfunc(--x);
printf ("M here 2\n");
printf (" %d,\n",x);
}
myfunc(5);
}
输出到来是:
[5]M here 1
[4]M here 1
[3]M here 1
[2]M here 1
[1]M here 1
[0]M here 1
0,M here 2 [0]
0,M here 2 [1]
1,M here 2 [2]
2,M here 2 [3]
3,M here 2 [4]
4,M here 2 [5]
不过,我被困在如何
0,M here 2 [0]
0,M here 2 [1]
1,M here 2 [2]
2,M here 2 [3]
3,M here 2 [4]
4,M here 2 [5]
是不是应该在
0,M here 2 [0]
'--x'递减'x' * *前把它传递给'MYFUNC()' –
是啊,得到了..但我想知道,X是如何第一次 0后递增,男这里2 [0] –
@ notbad.jpeg:'x'无法传递给函数! C严格按照价值传递! – Olaf