0

If I write code like this:

int main()
{
    int const maxn = 1e5 + 5, maxk = 450;
    int dp[maxn][maxk];
}

I will get the Runtime Error:

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

But If I move variables to global scope, everything will work fine.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • 3
    Compilers usually store local variables on the stack. The stack is a limited resource. On Windows the default stack size for a process is only a single megabyte, on Linux it's eight megabytes. Assuming 4-bytes `int` (which is typical), how large in bytes is your matrix? – Some programmer dude Oct 27 '21 at 11:12
  • On an unrelated note, the name `dp` is a common abbreviation for **d**ynamic **p**rogramming, which is a common way to solve problems on so-called "competition" or "online judge" sites. If you're a beginner and want to learn programming and C++, the best advice you could get right now is to stay as far away from such sites as possible. They are not any kind of teaching or learning resource. Using them as such will only harm your learning. Get [some good books](https://stackoverflow.com/a/388282/440558) and take classes instead. – Some programmer dude Oct 27 '21 at 11:16
  • 180000000 bytes. But why is this working when I move it to global? – Intolighter Oct 27 '21 at 12:08
  • Global variables aren't stored on the stack. – Some programmer dude Oct 27 '21 at 12:13

0 Answers0