1. ## Multidimensional Arrays?

What are multidimensional arrays used for? Until recently, I haven't found much use for them until I read something about designing a grid and it says use a multidimensional array with the sizes of the grid to your liking (i.e. if you want the grid to be 20x40, than it'll look like this: int grid[20][40]).

I dont really understand them and how to use them.

2. Your screen is a 2D array of pixels / characters.
A map for a game could be a 2D array.
Matrices are often stored in a 2D array.

3. an array of an array of pointers is also another possible application.. like extracting data from a multiline edit box.. have the first dimension of the array stand for each line of text.. and have the second dimension stand for the line of text itself..

Code:
`cout << text[2][0] ;       // would print out the second line of text...   until it reaches the '\0'  null terminator`

4. Originally Posted by Salem
Your screen is a 2D array of pixels / characters.
A map for a game could be a 2D array.
Matrices are often stored in a 2D array.
Unless you used specialised storage techniques, a matrix is usually a 2 (or more) dimensional array

A map of the planets in a solar system would probably be three dimensional, as would a map of solar systems in a galaxy.

If your program is to support display on multiple screens, it may use an array of screens. If each screen is a 2D array of pixels/characters than an array of screens could also be represented as a 3D array of pixels/characters.

5. Based on your replies, this is what I got.

Multidimensional arrays can be used for text editing.
Code:
`int text[4][20] = "16";`
Wouldnt that statment assign 16 to position 19 at line 4?

And if I wanted to created a 2D map grid the size of 40x40, i would make it like below:
Code:
`int map_grid[40][40];`
I think i grasp the basics of these. But isn't there a tutorial that explains these a bit more in-depth than the ones here?

Code:
`int text[4][20] = "16";`
Wouldnt that statment assign 16 to position 19 at line 4?
No. That is a syntax error.

Do you have anything in particular in mind? It's much easier than dreaming up something that you care nothing about.

7. I want to know how to work with them. As of now, im completely lost at this...

8. Code:
```#include <iostream>
#include <iomanip>

int main()
{
int value[4][3] = { {1,2,3}, {4,5,6}, {7,8,9}, {10,11,12} };
for ( int i = 0; i < 4; ++i )
{
for ( int j = 0; j < 3; ++j )
{
std::cout << std::setw(2) << value[i][j] << ' ';
}
std::cout << '\n';
}
return 0;
}

/* my output
1  2  3
4  5  6
7  8  9
10 11 12
*/```
But it is always beneficial to have a problem to solve before you go looking for solutions.