COHERENT manpages
This page displays the COHERENT manpage for recursion [Definition].
List of available manpages
Index
recursion -- Definition
Recursion is the technique by which a program or function calls itself.
Because under C, all variables in a function function have local scope;
therefore, when a function calls itself, it in effect recreates itself but
with a fresh copy of each of its variables. The ``states'' of the previous
call or calls to that function are stored on the stack, and are not
modified when the function calls itself.
Recursion is a useful way to loop through a complex procedure. Be careful,
however, that you do not lose track of how the number of times you have
called a given function; and be careful not to pile the stack too high, or
you may have problems.
Example
The following program demonstrates recursion. In it, the function recur()
calls itself ten times.
#include <stdio.h>
main()
{
printf("Before recursion ... \n");
recur(1);
printf("After recursion ... \n");
}
recur(level)
int level;
{
printf("Entering call to recur() number %d\n", level);
if (level < 10)
recur(level+1);
printf("Leaving call to recur() number %d\n", level);
}
See Also
programming COHERENT