# two dimensional arrays

• 05-01-2002
ssjnamek
two dimensional arrays
i have a descet idea on one dimensional arrays but two dimensional arrays blew me out went way over my head so if anyone can clear up for me what they do and there purpose and litle sample to start with id appreciate it as i was trying to skip over that section in my book and go back to it but my book keeps using it so i figured id see if anyone can help me out here thanx bye
• 05-01-2002
jdinger
Just think of it as a rectangular grid.

int i[3][3];

3 elements across x 3 elements down.
[][][]
[][][]
[][][]

So if you did this:
Code:

```int i[3][3]; i[0][0]=1; i[0][1]=2; i[0][2]=3; i[1][0]=4; i[1][1]=5; i[1][2]=6; i[2][0]=7; i[2][1]=8; i[2][2]=9;```
You could imagine it like this:
[1][2][3]
[4][5][6]
[7][8][9]
• 05-01-2002
ssjnamek
so would this be good forlike making charts on output or what?
• 05-01-2002
golfinguy4
That is one way to use them. For example, tic tac toe could use one for knowing where the X's and O's are.
• 05-01-2002
itld
howdy, this is a simple demo on how to initialize and access a 2 dimensional array.
#include <iostream>
#include <stdlib.h>

Code:

```int main() {   int stuff[5][5];//initialize a 6 by 6 array   stuff[2][2] = 22;//place 22 in the location stuff[2][2]   stuff[3][2] = 32;//place 32 in the location stuff[3][2]   stuff[0][1] = 01;//place 01 in the location stuff[0][1]   cout<<"location [2][2] contains: "<<stuff[2][2]<<endl;//obvious   cout<<"location [3][2] contains: "<<stuff[3][2]<<endl;//obvious   cout<<"location [0][1] contains: "<<stuff[0][1]<<endl;//obvious   return 0; }```
regards
M.R.