What is a function called when it calls itself directly or indirectly?
int factorial(int n)
{
if(n <= 1)
return 1;
return n * factorial(n - 1);
}
Options
-
A.
Inline function
-
B.
Recursive function
-
C.
Friend function
-
D.
More than one of the above
-
E.
None of the above
Correct Answer (Detailed Explanation is Below)
B.
Recursive function
Detailed Explanation
Answer: (B) Recursive function
A function that calls itself is called a recursive function.
In the given example, factorial() calls itself using factorial(n - 1).
A recursive function normally requires a base condition to stop further recursive calls. Here, n <= 1 acts as the base condition.