C++ - Recursion
Overview
Estimated time: 30–40 minutes
Write functions that call themselves with proper base cases and termination.
Learning Objectives
- Write recursive functions with base cases.
Example
int fact(int n){
return (n<=1) ? 1 : n*fact(n-1);
}
Common Pitfalls
- Missing base cases cause stack overflow.