What do you call a function that calls itself (is this called recursion)?

I am trying to understand what you are calling a function that is referencing itself. Is this recursion? Or is it just a function of self-reference?

+4
source share
3 answers

This is a recursive function. Direct recursion is when a function calls itself.

+5
source

A function that calls itself, as you suspect, is called "recursive."

+2
source

Recursive or self-recursive is what I usually call it. Just be careful that you don't get stuck in the loop calling yourself, eventually blowing up the stack.

Also remember your variable. Declare variables as static if they are needed for sharing at all levels of recursion (or declare them outside the function). Pass variables to functions if you need specific information passed from one level to another. And finally, use local variables in the functions needed to maintain state for the current recursion level. Local variables will make a copy on the stack for each recursion level you call and return to the previous values ​​for each recursion that is unwound.

0
source

All Articles