A recursive function calls itself, which can solve interesting programming puzzles, such as mazes, and make advanced mathematical calculations. It's important that a recursive function has an exit condition or it keeps calling itself until the stack overflows.
- [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 … as is done in this update to the code, …
- Writing your first C program
- Working the C development cycle
- Adding comments to code for clarity
- C language data types
- Declaring variables
- Making new data types
- Typecasting variables
- Using math, assignment, and logical operators
- Creating for and while loops
- Nesting loops
- Creating functions
- Returning values from functions
- Passing arguments to functions
- Creating recursive functions
Skill Level Intermediate
C: Data Structures, Pointers, and File Systemswith Dan Gookin2h 57m Intermediate
1. The Fundamentals of C
2. Variables and Values
3. Operators and Math
4. Decisions and Loops
Next steps1m 38s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.