C++ Recursion
Recursion is a programming technique that the function calls itself is called Recursion, which means that if a program allows the programmer to call a function within in the same function, it’s called Recursion call of the function.

Syntax:-
void recursion() { recursion(); /* function calls itself */ } int main() { recursion(); }
Example:-
#include <iostream> using namespace std; int fact(int a){ if (a==0 || a==1){ return 1; } else{ return a*fact(a-1); } } int main(){ int n, i; unsigned long factorial = 1; cout << "Enter the factorial number :"; cin >> n ; factorial= fact(n); cout << "Sum of two numbers value is :" << factorial << endl; return 0; }

The programmer has to define exit condition from the function, if not it will go into an infinite loop.
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.