Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Recursion is an advanced feature supported by C++ language. Recursion means a function calling itself. Consider the problem of finding a factorial of a number. In the example, we can clearly see that Fact(5) is calling Fact(4) and so on.
Fact(5) = 5 x 4 x 3 x 2 x 1
= 5 x Fact(4)
= 5 x 4 x Fact(3)
= 5 x 4 x 3x Fact(2)
= 5 x 4 x 3x 2 x Fact(1)
= 5 x 4 x 3x 2 x 1 x Fact(0)
= 5 x 4 x 3x 2 x 1 ( Fact(0) =1)