Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Multi-Dimensional Arrays | Data Types and Arrays
C++ Intermediate | Mobile-Friendly
course content

Зміст курсу

C++ Intermediate | Mobile-Friendly

C++ Intermediate | Mobile-Friendly

1. Data Types and Arrays
2. References & Pointers
3. Dynamic Memory
4. Functions

book
Multi-Dimensional Arrays

As we remember, an array is a set of variables that allows you to store several values of the same type. A multi-dimensional array is an array of arrays. To declare such an array, specify the type of variables it contains and the name of the array, followed by the square brackets where we indicate how many elements each of the main and subarrays have.

For example:

python

Here we declared a two-dimensional 3x4 integer array a. It means that the array has 3 elements, and each of them is an array with 4 elements. Let’s visualize the array as the table:

Remember that indexing in arrays starts from 0.

As with ordinary arrays, multi-dimensional arrays may be declared by specifying each element in curly braces separated by a comma:

python

We can get access to the element of the 2-dimensional array by specifying the name of the array with its row and column indexes:

python

Each pair of square brackets in an array declaration adds another dimension. You can create arrays of any dimension you want. Further in this course, we will only work with two-dimensional arrays.

question-icon

Print the second element in the first row of the array.

int numbers[3][2] {{1, 2}, {3, 4}, {5, 6}};
cout << numbers
;
2

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 6
Ми дуже хвилюємося, що щось пішло не так. Що трапилося?
some-alt