Sams Teach Yourself C++ in 21 Days

(singke) #1
A good example of a two-dimensional array is a chess board. One dimension represents
the eight rows; the other dimension represents the eight columns. Figure 13.3 illustrates
this idea.

418 Day 13


FIGURE13.3
A chess board and a
two-dimensional array.

1 2 3 4 5 6 7 8
2345678

6 7
4 5
2 3
0 0 1
6 7
4 5
2 3
1 0 1
6 7
4 5
2 3
2 0 1

6 7
4 5
2 3
7 0 1

Suppose that you have a class named SQUARE. The declaration of an array named Board
that represents it would be
SQUARE Board[8][8];
You could also represent the same data with a one-dimensional, 64-square array. For
example:
SQUARE Board[64];
Free download pdf