A [1000] [1000] program crash, 1000 program crash
1000*1000 is greater than 65536. If not required, there is no need to open up so much space. Because these spaces are applied on the stack (if they are local variables), the stack space is limited and valuable, opening up too much space and not applying it is likely to cause memory leakage.
The array subscript is generally of the int or unsigned int type. on 32-bit machines, it is sufficient to define a subscript range of more than 2 billion. Generally, an error in a large array is not caused by it, but because the array consumes the stack space.
To define a large array, try to put it in the heap instead of the stack. Stack space is very limited and should not be wasted.
There are many ways to put it in the heap: Create with new, define it as a static array, define it as a global array, and so on.
Details:
Static int a [1000] [1000];
Add static before the local array declaration that occupies a large memory space to move it from the stack data segment to the global data segment.
Int (* p) [MAX] = new int [MAX] [MAX];