Define recursion in C.A programming technique in which a function may call itself. Recursive programming is especially well-suited to parsing nested markup structures
Calling a function by itself is known as recursion. Any function can call any function including itself. In this scenario, if it happens to invoke a function by itself, it is recursion. One of the instructions in the function is a call to the function itself, usually the last statement. In some ways it is similar to looping. When the result of ‘one time call of a function is the input for the next time call of the function’, recursion is one of the best ways. For example, calculating factorial, in which the product of previous digit factorial is the input for the next digit’s factorial.
The process of calling a function by itself is known as recursion. Recursion is generally used when the result of the current function call is the input to the successive call of itself. For example, ‘factorial of a digit’. By definition, the factorial of the current digit is the factorial of its previous digit and the digit. In order to get the factorial of the previous digit, the same function should return the factorial.
Thus the result of the previous execution of the function is one of the inputs of the current execution. The process continues until an exit condition returns true.
|