0

I have the code:

#include <iostream>

using namespace std;

int main()
{
    int a[1000000] = { 1, 2 };

    return 0;
}

When I run it in visual studio I get:

 (process 17300) exited with code -1073741571

With

int a[1000000] = {};
a[0] = 1;

I get the same error. If I lower it to 100000, it works fine. How can I avoid this error?

  • 2
    ***How can I avoid this error?*** Use a vector instead of a an array. Remember on windows / Visual Studio the default stack size is 1 MB total. – drescherjm Oct 09 '22 at 17:40
  • The error is a stack overflow use this web page to decode the error: [https://james.darpinian.com/decoder/?q=-1073741571](https://james.darpinian.com/decoder/?q=-1073741571) – drescherjm Oct 09 '22 at 17:42
  • allocate on the heap instead – AndersK Oct 09 '22 at 17:43
  • Declare the array as `static`. Usually there is more memory available in the `static` area than on the stack. – Thomas Matthews Oct 09 '22 at 17:48

0 Answers0