Two-dimensional array in C language

‮al.www‬utturi.com
Two-dimensional array in C language

syntax

type arrName[rows][cols];

example:

int score[4][5];

Assign values to a 2-dimensional array

score[0][0] = 10;
score[1][3] = 50;

Initializing 2-D Arrays while Creating

method 1

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

method 2

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

filled with 0

We can also skip elements, which are automatically populated as 0.

int bonus[2][3] = {
  {1, 2},
  {3}
};

same as:

int bonus[2][3] = {
  {1, 2, 0},
  {3, 0, 0}
};
Created Time:2017-08-28 07:19:20  Author:lautturi