Why does this code not cause a segmentation fault when it is supplied with input 1 1000?

```
#include <iostream>
#define MAX 1000
using namespace std;
long long dp[MAX] = {-1};
long long func(int n)
{
if(dp[n] > 0)
{
return dp[n];
}
else {
return dp[n] = (n * n) + func(n - 2);
}
}
int main()
{
dp[0] = 0;
dp[1] = 1;
dp[2] = 4;
int T;
cin >> T;
while (T--)
{
int n;
cin >> n;
cout << func(n) << endl;
}
return 0;
}
```