2D Arrays

Created by Emília Pietriková / ema

2D

Declaration

// general
type name[rows][cols];
// example
int board[9][9];

Initialization

int array[2][3] = {
    {1,2,3},
    {4,5,6}
};
int array[][3] = {
    {1,2,3},
    {4,5,6}
};

Indexes

int array[][3] = {
    {1,2,3},    // [0][0], [0][1], [0][2]
    {4,5,6}     // [1][0], [1][1], [1][2]
};

1D in Memory

int array[] = {1,2,3,4,5};

2D in Memory

int array[][4] = {
    {1,2,3,4},
    {5,6,7,8}
};

3D

Questions?