# Thread: Differennce between one and two dimensinal arrays

1. ## Differennce between one and two dimensinal arrays

Hi
I am studying arrays... So i have a simple question.. I better to use one dimensional arrays or 2 dimensinal arrays? And why? I mean who is faster and why? Wich is better to use for compare the valus of 2 equal arrays??

2. It depends on the data. If you need to locate the X-Y location of a pixel in a window, that's a 2-d array. Bitmaps are composed of 3 colors per pixel, so bitmaps are 3-d arrays.

AFAIK, there is no speed difference. Physical memory is one-dimensional and multi-dimensional arrays are a conceptual abstraction.

3. 1D arrays can be usefull for holding filenames for image files for a game. You can than use a 'for' loop to search through the array and load the images into memory. 2D arrays can be used for displaying a chess/checker game in a console app. They can also be used for graphical games, such as 'Breakout', to display a map. An array of type 'int' will be filled with numbers, which correspond to certain color tiles. There are many uses for both types, and again, depends on the situation.

4. They are really the same neither is faster. It's just a style difference. 2D arrays are stored in continuous memmory, just like 1D arrays.

You want your code to be easy to read, so use which ever makes sence.

5. It is however of note to mention that there is no such thing as a multidimensional array in C++. A 2D array is in fact an array of arrays. It is still a unidimensional array, only each element is storing an array. A 3D array is in fact an array storing arrays each of them storing an array. A 4D array is... ad aeternum.

Code:
```/* An array called myarray with 2 elements. Each element is an array of 3 ints. */
int myarray[2][3];```

6. They are really the same neither is faster. It's just a style difference. 2D arrays are stored in continuous memmory, just like 1D arrays.
Not true.

How do you suppose indexing into a 2D array at an arbitrary offset is done without using a multiply?

??