Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Recursive call of c language function
Recursive call of c language function
Call the function f first, and then assign the return value to z, but this function is wrong, there is no exit condition, and it cannot be stopped. For example.

int f(int x)

{

If (x==0)

{

Returns1;

}

other

{

Returns x * f (x-1);

}

}

Suppose f(3)

therefore

The first time f(3):x! =0, call f(2)

The second f(2):x! =0, call f( 1)

The third f( 1):x! =0, call f(0)

The fourth f( 1):x==0, and returns 1.

Call f( 1) for the third time: return1*1=1;

Call f(2) for the second time: return 2 *1= 2;

Return the first call f(3): return 3 * 2 = 6;

The result of f(3) is 6.