I am trying to find the maximum value I can put for each dimension in a 2D array, ... |
Gamer2015 has already pointed out the limit is actually on the number of elements in your array, rather than the individual dimensions. Afterall, (normal) computer memory is linear.
For an array with multiple dimensions you need to keep the dimensions small enough that their product multiplied by the size of each element is less than or equal to the available memory. e.g. array
int data[N][M];
it's going to take N x M x sizeof(int) bytes (int can be 16, 32, 64 bit, that is 2, 4, or 8 byte. Or even more.)
(Unless you arbitrarily decide that the maximum size of a square array (cube array, etc) sets the maximum for an array?)
Indidentally, the size Gamer2015 is talking about is assuming you're allocating the array with new, where you can access a lot of memory. If you are working with a stack variable the amount of space is a lot smaller. With Microsoft Visual Studio's C++ compiler, the default stack size is 1 MB per thread. And this has to hold all the variables in the functions on the current call stack.
If a stack variable could use the whole of the stack memory then, for a square array of 32-bit ints, the maximum value of the dimensions would be 512. A good bit smaller even than USHRT_MAX = 65535.
Andy