100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
C++

Multidimensional Arrays in C++

Understand multidimensional arrays in C++ as arrays of arrays, how 2D arrays model rows and columns, and how row-major storage works.

ArraysBeginner7 min readJul 7, 2026
Analogies

1. Intro

A multidimensional array is simply an array of arrays. The most common form is the 2D array, which can be thought of as a table or grid with rows and columns — useful for representing matrices, game boards, or tabular data. C++ also supports 3D and higher-dimensional arrays, though 2D arrays are by far the most frequently used in everyday code.

🏏

Cricket analogy: A Duckworth-Lewis resource table is a grid of overs-remaining rows against wickets-lost columns — exactly the row-and-column structure of a 2D array, with rarer 3D tables adding a pitch-condition dimension.

2. Syntax

cpp
dataType arrayName[rowSize][columnSize];

// Example: a 3x4 grid (3 rows, 4 columns)
int grid[3][4];

3. Explanation

int grid[3][4]; conceptually creates 3 rows, each containing 4 columns — 12 int elements in total. Even though we think of it as a table, C++ stores a 2D array in a single contiguous block of memory, arranged in row-major order: the entire first row is stored, followed immediately by the entire second row, and so on. An element is accessed using two indices, grid[row][col], both zero-based, so grid[0][0] is the top-left element and grid[2][3] is the bottom-right element of a 3x4 grid. You typically use nested for loops — an outer loop for rows and an inner loop for columns — to fill or traverse a 2D array.

🏏

Cricket analogy: A int grid[3][4] scoring table for 3 innings by 4 quarters stores all 12 cells contiguously, first innings-one's four quarters, then innings-two's, row-major — grid[0][0] is the first quarter scored, grid[2][3] the last, filled with a nested loop over innings then quarters.

4. Example

cpp
#include <iostream>
using namespace std;

int main() {
    int grid[2][3] = {
        {1, 2, 3},
        {4, 5, 6}
    };

    for (int row = 0; row < 2; row++) {
        for (int col = 0; col < 3; col++) {
            cout << grid[row][col] << " ";
        }
        cout << endl;
    }

    return 0;
}

5. Output

text
1 2 3 
4 5 6 

6. Key Takeaways

  • A multidimensional array is an array of arrays; a 2D array models rows and columns.
  • Declare a 2D array with dataType name[rows][cols];, and access elements with name[row][col].
  • C++ stores 2D arrays contiguously in row-major order — the whole first row, then the whole second row, and so on.
  • Nested for loops (outer for rows, inner for columns) are the standard way to fill or traverse a 2D array.

Practice what you learned

Was this page helpful?

Topics covered

#CStudyNotes#Programming#MultidimensionalArraysInC#Multidimensional#Arrays#Syntax#Explanation#DataStructures#StudyNotes#SkillVeris