Home  >  Article  >  What does recursive calling of a function mean?

What does recursive calling of a function mean?

angryTom
angryTomOriginal
2019-07-24 14:38:2115941browse

What does recursive calling of a function mean?

Recommended tutorial: java tutorial

Recursive definition

Recursive calling is to call the current function in the current function and pass it to the corresponding parameters. This is an action. This action is performed layer by layer until the general situation is met. time, stop the recursive call and start returning from the last recursive call.

Detailed explanation of recursion

Before calling

When one function calls another function during the running , before running the called function, the system needs to complete three things:

  (1) Pass all actual parameters, return addresses and other information to the called function for storage;

  (2) Allocate storage area for local variables of the called function;

  (3) Transfer control to the entrance of the called function.

Calling

Before returning from the called function to the calling function, the system should also complete 3 tasks:

(1) Save the called function The calculation result of the function;

  (2) Release the data area of ​​the called function;

  (3) Transfer control to the calling function according to the return address saved by the called function. When there are multiple functions forming nested calls, the principle of returning first after the last call is followed.

Features of recursive functions

The structures of all recursive functions are similar.

  (1) The function must call itself directly or indirectly.

 (2) There must be a recursive termination condition check, that is, after the recursive termination condition is met, the own function will no longer be called.

 (3) If the conditions for recursive termination are not met, the expression involving the recursive call is called. When the function itself is called, the parameters related to the termination condition need to change, and they need to change in the direction of recursive termination.

Summary

The function calling principle is consistent with the implementation of the data structure stack. It also shows that function calls are implemented through the stack.

The above is the detailed content of What does recursive calling of a function mean?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn