Array indexing is based on zero.
This means that for: int foo[3] = {10, 20, 30};
foo[0] - 10foo[1] - 20foo[2] - 30
For multidimensional arrays, you should think of them as arrays of arrays.
So, this will create an array containing two int[3] s: int foo[2][3] = {{10, 20, 30}, {40, 50, 60}};
foo[0][0] - 10foo[0][1] - 20foo[0][2] - 30foo[1][0] - 40foo[1][1] - 50foo[1][2] - 60
C supports partial initialization. In which it will default to all non-initialized values ββequal to 0.
So, if you must do this: int foo[3] = {5};
foo[0] - 5foo[1] is 0foo[2] is 0
Similarly for a multidimensional array: int foo[2][3] = {5};
foo[0][0] - 5foo[0][1] is 0foo[0][2] is 0foo[1][0] is 0foo[1][1] is 0foo[1][2] is 0
source share