This chapter expands our discussion on one-dimensional arrays to two dimensional arrays. A two dimensional array is a data structure that contains a collection of cells laid out in a two dimensional grid, similar to a table with rows and columns although the values are still stored linearly in memory. Each cell in a two dimensional array can be accessed through two indexes that specify the row number and column number respectively. Like s one dimensional array, the range of each index is from zero to the size of the row or column minus one. A nested for loop is commonly used to initialize, manipulate, and access the values in a two dimensional array.
6. 2D Array of int
Answer:
Yes, just as for 1D arrays.
If you want a collection of a variety of types, you probably want to define your own class to contain them.
2D Array of int
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.
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.
|
Question 6:
What does the program print out?