Possible Duplicate:
How do I use arrays in C++?
would there be any Memory issues or execution issues or any merits or demerits of using 1D array of size 'mn' instead of using 2D array of size mxn ?
Possible Duplicate:
How do I use arrays in C++?
would there be any Memory issues or execution issues or any merits or demerits of using 1D array of size 'mn' instead of using 2D array of size mxn ?
In memory, they are represented exactly the same. The difference is semantic. If you're operating on a matrix, accesing an element as
x[i][j]
is more intuitive than
x[i*n + j]
Both the arrays 1D and 2D are exactly the same in memory perspective. The only difference would be syntactically. 3D arrays would only be useful to design the logic around the problem.
e.g:
array x[m*n]
array x[m][n]
Both are same when we talk in terms of memory
You can create the 2D array of int and a pointer to int.
Then you can set the pointer to the adress of the first element
int* singleDimention=&twoDimension[0][0];
If you process all items regardless of their 2D coordinates, it will be faster (slightly) to do it using one dimension array.
numItems=n*m;
for(i=0;i<numItems;i++){
do stuff with singleDimention[i];
}