I expected the code below to print the sequence 0 1 2 3.
Instead I got a recursion call runtime error (causing a stack overflow).
Can you explain why ?
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void print(int n)
{
if (n < 0)
return;
if (n == 0)
{
cout << n << " ";
return;
}
print(n--);
cout << n << " ";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int num = 3;
print(num);
return 0;
}