1d arrays and multi array question

what is the max size that you may put in a single demensional array?

what is the purpose of having multi demensional arrays?
if i wanted int number[5][5]
wouldn't it be easier to choose int number[25] instead?
Last edited on
the purpose of multi-dimensional arrays is just to make them more closely represent some grid structure. Say for example if you were representing a connect four board, you could make a 7x6 array. You could also just make a 1d array with 42 elements and then calculate the offset (column*7+row).

I prefer to use 1d arrays as there are several caveats with multi dimensional arrays, there used to be a great article on this site about the downsides to multidimensional arrays and I was going to link you to it but I can't seem to find it...
There is no max size to an array--as long as you have the memory available to allocate then you can make it. However it might be a good idea to dynamically allocate large arrays.

Example:
1
2
3
int *number=new number[10000000];
//use number[10000000]
delete [] number;    //make sure to call delete[] if you used new[]. It deallocates the memory so that you don't have a memory leak. 
so multi demensional arrays allows easy grid structuring?

so can you do everything with a single demensional array that you could do with a multi demensional array???

thanks quirkyusername and mavvie


thanks in advance,

Last edited on
so can you do everything with a single demensional array that you could do with a multi demensional array???

yes, you can just as easily use a 1d array, and it may even prevent some problems.

thanks quirkyusername and mavvie

no problem, welcome to the forum it is wonderful here.
Topic archived. No new replies allowed.