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.

01-13-2006

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.

01-13-2006

The Brain

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

01-13-2006

grumpy

Quote:

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.

01-13-2006

CreatedByShadow

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?

01-13-2006

Dave_Sinkula

Quote:

Originally Posted by CreatedByShadow

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.

01-13-2006

CreatedByShadow

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