Recursion
Some computer programming languages allow a module or function to call
itself. This technique is known as recursion. In recursion, a function α either
calls itself directly or calls a function β that in turn calls the original function α.
The function α is called recursive function.
Many programming languages implement recursion by means of stacks.
Generally, whenever a function (caller) calls another function (callee) or itself
as callee, the caller function transfers execution control to the callee. This
transfer process may also involve some data to be passed from the caller to the
callee.
This implies, the caller function has to suspend its execution temporarily and
resume later when the execution control returns from the callee function. Here,
the caller function needs to start exactly from the point of execution where it
puts itself on hold. It also needs the exact same data values it was working on.
For this purpose, an activation record (or stack frame) is created for the caller
function.
This activation record keeps the information about local variables, formal
parameters, return address and all information passed to the caller function.
int fact(int n)
{
if (n < = 1) // base case
return 1;
else
return n*fact(n-1);
}