引入递归
在调用函数的过程中又出现直接或者间接调用函数本身,称为函数的递归调用。
直接调用:
int test(int x){
int a,b;
b=test(a);
return(2*b);
}
这就是直接调用,即在本函数体内,再次调用其自身。
间接调用:
int test (int x){
int test2(int z);
int a,b;
b=test2(a);
return (2*b);
}
int test2 (int z){
int c=2*z;
test(c);
}
上面就是间接调用了,虽然函数体本身并没有调用自身函数,但是调用了其他函数,其他函数又掉用了其主调函数,这就是简介的进行递归。