2D Arrays & Matrix Grid Processing

🟡 Intermediate

📖 Definition

A 2D array (T matrix[R][C] or std::vector<std::vector<T>>) stores elements in row-major contiguous memory order, accessed via double subscript indexing (matrix[row][col]).

💡 Code Example

#include <iostream>

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

    for (int r = 0; r < 2; ++r) {
        for (int c = 0; c < 3; ++c) {
            std::cout << matrix[r][c] << " ";
        }
        std::cout << "\n";
    }
    return 0;
}