Thread: Need help to understand Arrays

1. Need help to understand Arrays

Alright, so I read through the Arrays tutorial on this website -
Arrays in C and C++ - Cprogramming.com

And so I tried using the tutorial codes -

Code:
#include <iostream>

using namespace std;

int main()
{
int x;
int y;
int array[8][8]; // Declares an array like a chessboard

for ( x = 0; x < 8; x++ ) {
for ( y = 0; y < 8; y++ )
array[x][y] = x * y; // Set each element to a value
}
cout<<"Array Indices:\n";
for ( x = 0; x < 8;x++ ) {
for ( y = 0; y < 8; y++ )
cout<<"["<<x<<"]["<<y<<"]="<< array[x][y] <<" ";
cout<<"\n";
}
cin.get();
}
And when the program is launched, it prints all this-

So.., here is what I don't understand. In the left brackets of each column ( I assume it's where the x's are) shows 0 - 7. But in the right brackets of each column ( I assume it's where the y's are) show 0 in the first column and 1 on the second column, 2 on the third column and so on... That is what I don't understand.

huh ?_? huh <- May someone please give me an easier explanation. Thanks.

2. The left brackets hold the row, while the right brackets hold the column. Can't you see a pattern on how these values are printed?

3. Originally Posted by GReaper
The left brackets hold the row, while the right brackets hold the column. Can't you see a pattern on how these values are printed?
I still don't understand. And it's the numbers that has my fingers scratching my head.

4. Originally Posted by Conti
I still don't understand. And it's the numbers that has my fingers scratching my head.
A 2D matrix has rows and columns. Think of it like a chess board for example:
Code:
A B C D E F G H
1                 1
2                 2
3                 3
4                 4
5                 5
6                 6
7                 7
8                 8
A B C D E F G H
How do you determine, with words, where a pone is or what your next movement will be?

5. Originally Posted by GReaper
A 2D matrix has rows and columns. Think of it like a chess board for example:
Code:
A B C D E F G H
1                 1
2                 2
3                 3
4                 4
5                 5
6                 6
7                 7
8                 8
A B C D E F G H
How do you determine, with words, where a pone is or what your next movement will be?
Ah. I understand now. +1 to you chap ^.^

6. Another way of visualizing it (which scales beyond 2 dimensions) is that you have some small boxes with some value in them.
Then you take those boxes and put them into one big box.
And finally, you create several of those big boxes (all of which contains all those small boxes inside them).
For every dimension you add, you repeat this.