Recursion is the process of a function calling itself, and the function that is doing it is referred to as a recursive function. A base condition and a recursive condition make up the recursive function.
Recursive functions need a base case to ensure that the recursion ends; otherwise, they will run indefinitely, which is not what you want. The basic case is the scenario in which the function doesn’t recur. The base case, for instance, is when we attempt to use recursion to get the factorial of a number and our number ends up being less than 1.
The formula used to get a number’s factorial is an illustration of a recursive function.
int factorial(int n){
if (n == 0 || n == 1){
return 1;
}
return n * factorial(n - 1);
}