C++ valarray vs array size allocation

I am allocating a multidimensional valarray of size 2000×2000 and it is working smoothly.

valarray<valarray<int>> D(valarray<int>(-2,2000), 2000);
D[1999][1999] = 2000;

However, if I try to allocate a normal array and access an element, I get segmentation fault.

int A[2000][2000];
A[1999][1999] = 2000;

Both are on the stack, why this difference ?

Source: Windows Questions C++

LEAVE A COMMENT