next up previous
Next: Reference Parameters Up: Functions Previous: Function Overloading

Recursion

Recursion is the process of defining something in terms of itself. Recursion is sometimes called circular definition. A function that calls itself is said to be recursive.

Example
// this program finds the factorial (n!) of an integer #include <iostream.h>
factr(int n);
main()
cout << "4 factorial is "<<factr(4);
return 0;
}
factr(int n)
{
int answer;
if(n==1)return(1);
answer=factr(n-1)*n;// calling the function within itself
return(answer);
}



Yousef Haik
2/23/1998