Yes, just as for 1D arrays.
If you want a collection of a variety of types, you probably want to use a class to contain them, not an array.
int
The following program creates a 2D array of int that implements
the gradeTable example.
Details about declaring and constructing 2D arrays will
be explained later.
| Row | Col | ||||
|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | |
| 0 | 99 | 42 | 74 | 83 | 100 |
| 1 | 90 | 91 | 72 | 88 | 95 |
| 2 | 88 | 61 | 74 | 89 | 96 |
| 3 | 61 | 89 | 82 | 98 | 93 |
| 4 | 93 | 73 | 75 | 78 | 99 |
| 5 | 50 | 65 | 92 | 87 | 94 |
| 6 | 43 | 98 | 78 | 56 | 99 |
The declaration of gradeTable uses an
initializer list as a short-cut way to create a 2D array
object and place values into it.
The list contains 7 rows each separated by a comma;
each row is a list of values.
What does the program print out?