Two Dimensional Arrays

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.

13. Usual View of a 2D Array


Answer:

Yes

Usual View of a 2D Array

Annotation 2020-03-26 211459Usually you think of a 2D array as a table, not the complicated structure of the previous page. For example,

int[][] uneven = 
    { { 1, 9, 4 },
      { 0, 2},
      { 0, 1, 2, 3, 4 } };

is usually thought of as like the table on the right. Only occasionally do you have to think of "arrays of references to 1D arrays."

Now consider how you would print out every element contained in array uneven.


Question 13:

  • How many rows must be printed?
  • How many cells in each row must be printed?