Multidimensional arrays

A multidimensional array is an array that contains one or more arrays, where each array within the multidimensional array can be seen as an element of the outer array. In other words, a dd-dimensional array is an array of (d1)(d-1) dimensional arrays.

For instance, a 2D (two-dimensional) array can be visualized as an array of single-dimensional arrays.

Let’s learn how to make these multidimensional arrays in C++. For now, we’ll only focus on 2D arrays. We can easily generalize and extend the same syntax by adding further dimensions.

Creating a 2D array

A 2D array is often represented as a matrix with rows and columns. To declare a 2D array in C++, the following syntax is typically used:

Get hands-on with 1200+ tech skills courses.