Arrays 2/2Arrays 2/2

There are also two-dimensional arrays. Two-dimensional arrays are arrays whose elements are other arrays. Such arrays are very similar to tables, with rows and columns.

To declare such an array, one more pair of square brackets is required:

The picture shows an array with three elements, which are also arrays.

  • Row a[0]... is the first element of the array;
  • Row a[1]... is the second element;
  • Row a[2]... is the third element.

An array that is an element of another array is called a nested array.

You can also access the elements of a nested array through indices and another pair of brackets:




Why specify the data type and size of an array? - So that the compiler knows how much memory needs to be allocated for your data, and do not forget - that the array must contain data of the same type!

To use arrays to the fullest, in the following lessons, we will study loops. With the help of loops, we can automate work with arrays, for example, display an array's elements in turn (or according to some specific algorithm), or write text to arrays. Why do we need text in arrays? - Find out in the next lesson!


What is the output of this code?

Select the correct answer

Everything was clear?

Section 2. Chapter 5