Multi-Dimensional Arrays

Array Initializers

It is possible to use an initializer with a multidimensional array. For instance, the following examples create several small arrays and initialize their elements:

Annotation 2020-03-26 213023

The first of these declarations creates a 2 ⇥ 3 array of integers. The second example creates a 2 ⇥ 2 array of characters, and the third example creates an array of double consisting of three rows, each of which has a different number of elements. The first row contains three elements, the second contains two elements, and the last row contains four elements. As this last example shows, the rows in a multidimensional array don't all have to have the same length.

Using initializers, as in these examples, is feasible only for relatively small arrays. To see why, just imagine what the initializer expression would be for our three-dimensional rainfall array. It would require 4,160 = 10 ⇥ 13 ⇥ 32 zeroes, separated by commas!

Annotation 2020-03-26 213119