Why an infinite recursive function gives TLE (SIGSTP) in CodeChef IDE instead of giving segmentation fault?
How can 5 second be not enough to fill up the stack size?
Code
#include <bits/stdc++.h>
using namespace std;
int fun(int n) {
return fun(n - 1) + fun(n - 2);
}
int main() {
cout << fun(100) << '\n';
}
The compiler might be doing tail call optimisation, in which case the stack space used will be small and constant.
Edit:
Although I’ve just tried this on my machine and it segfaulted after 0.33 seconds, so maybe not (gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04), with -O3).