Functions: Recursions
Applies To: C++Builder 1 or higher
Category: C++ Language
- When the function calls itself, it is called recursion. Indirect recursion occurs when the function calls another function that then calls the first one. Direct recursion occurs when the function calls itself in its function body.
-
- For example, recursion is usually used when calculating the factorial of a number. Here's an example:
-
- int factorial(int number)
- {
- if(number == 1)
- return 1;
-
- number *= factorial(number - 1);
- return number;
- }
C++Builder Developer's Network
Copyright © Yoto Yotov