Recursion is the process of defining a function which calls itself from within its body. Recursive function is a function which calls itself again and again till the condition which is specified is true. In recursive functions we must give the terminating condition that is the limit upto which a function calls itself otherwise it will become an infinite loop that is a loop that never ends.
Eg of recursion : Program to calculate factorial of a number using recursion
# include
int factorial(int n)
{
if(n <= 1)
return 1;
else
return n*factorial(n - 1);
}
void main()
{
int x = 5;
printf("factorial of %d is %d",x,factorial(x));
}
What is a Recursive function?
More Questions
- What are Loop statements or Iteration Statements?
- What is Function overloading?
- What are Inline Functions?
- What are the different types of Polymorphism?
- What are the different types of Conditional Statements?
- What is Dynamic Binding?
- What are the Friend functions?
- What are the different types of Branching Statements?