From the course: C Essential Training

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Creating recursive functions

Creating recursive functions - C Tutorial

From the course: C Essential Training

Start my 1-month free trial

Creating recursive functions

- [Instructor] A recursive function is one that calls itself. It's like a picture within the same picture or a door that opens into a room with a door that opens into the same room. Yes, this concept is mind-boggling but it has useful purposes. This code shows how it recursive function works though it's imperfect. The recurse function is first called in the main function, it has an argument of zero. Within the recurse function, the recurse function is called again, this time with variable a, which was passed and incremented. The value of variable a increases each time the recurse function calls itself. Calling a same function within itself is the basis of recursion, build and run the code. And on this system, the recurse function calls itself 43,178 times before the stack implodes and the program crashes, this isn't the outcome you want. To write a successful recursive function you must supply an exit condition…

Contents