recursive functions
#include <iostream>
using namespace std;
// recursive function
// is a function that calls itself
// usecase: devide problems in fractmens which can be solves recursively
unsigned long long factorial (unsigned long long n) {
if (n == 0)
return 1; // base case - stops recursion and prevents stack overflow error
return n * factorial(n-1); // recursion
}
int main() {
cout << factorial(8) << endl; // 40320
return 0;
}
anything that can be done recursively can be done iteratively
based on stack overflow error → rewriting of recursive actions into iterative actions can be necessary