C++ FunctionsLesson 29Free preview
C++ Recursion
This lesson is part of C++ · All levels
Summary
This lesson discusses recursion, a technique where a function calls itself to break up a problem into smaller cases. Every recursive call must have a stop condition (base case) so it doesn't run endlessly. Recursion is suitable for recursive pattern problems such as factorial, Fibonacci sequence, and data structure search.
Key points
- The recursive is a function that calls itself.
- Base case prevents endless calls.
- Each call stacks frames on the stack until the base case is reached.
- A classic example: a factorial n = n * Factorial(n - 1) with base 0! = 1.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.