Recursive Function

Recursive function :

Recursive function is the one in which a function calls itself recursively(repeatedly).

int func()

{

func();      //recursive call of func()

}

There must be an exit code for that function i.e. there should be a terminating condition for the function to stop calling itself otherwise the function will go in infinite loop and the program will crash.

Program crashes because when the function is called, a new function stack is created.With function calling itself continuously, new function stacks are also created continuously. At one point of time, this causes stack overflow ,if there is no break condition, and the program crashes

Recursion make the code look simpler and good but it is hard for a beginner to design a recursive logic and debug the errors in the recursion program.

Leave a Reply

Your email address will not be published. Required fields are marked *