|
|
|
|
|
|
|
As with one-dimensional arrays, each index expression must result in an integer value. |
|
|
|
|
|
|
|
|
Let's look now at some examples. Here is the declaration of a twodimensional array with 364 integer components: |
|
|
|
|
|
|
|
|
We can think of hiTemp as a table with 52 rows and 7 columns. The contents of each place in the table (each component) can be any int value. Our intention is that the array contains high temperatures for each day in a year. Each row represents one of the 52 weeks in a year, and each column represents one of the 7 days in a week. (To keep the example simple, we ignore the fact that there are 365and sometimes 366days in a year.) The expression hiTemp[2][6] refers to the int value in the third row (row 2) and the seventh column (column 6). Semantically, hiTemp[2][6] is the temperature for the seventh day of the third week. The code fragment shown in Figure 13-2 would print the temperature values for the third week. |
|
|
|
|
|
|
|
|
Another representation of the same data might be as follows: |
|
|
|
|
|
|
|
|
enum DayType
{
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY
};
int hiTemp[52][7]; |
|
|
|
|
|