What is recursion? What are the differences between direct and indirect recursion in c programming.
Answer: – Recursion is a little bit though, but if we keep track of the program, in which sequence it is executing, it is easy to understand. Recursion in one of the most dominant tools used in the C programming technique there are various situations when we need to execute a block of statements for a number of times depending on conditions at that time recursion in useful. Recursion is used to solve problem, which has iterations in reverse order. Data structure also support recursion, for example, tree support recursion. Various programs are solved with the use of recursion. The major application of recursion is game programming where series of steps can be solved with recursion. There are two types of recursion used in C programming languages are called direct and indirect recursion. There are number of differences between direct and indirect recursion they are: –
- In the direct recursion, only one function is called by itself but in indirect recursion more than one function are by the other function and number of times.
- The indirect recursion does not make any overhead as direct recursion.
- The direct recursion called by the same function while the indirect function called by the other function.
- In direct function, when function called next time, value of local variable will stored but in indirect recursion, value will automatically lost when any other function is called local variable.
- Direct function engaged memory location while local variable of indirect function not engaged it.
- Structure of indirect function differs from direct function. Structures of both direct and indirect functions are as follows.
Direct function |
Indirect function |
int num() { . . . . . . . . . . int num(); } |
int num() { . . . . . . . . . . int sum(); } int sum() { . . . . . . . . . . int num(); } |