Lesson 8 Arrays_2D
Lesson 8 Arrays_2D
Item1 Item2
Item3
table[0] 0 1 2 3 0
table[1] 1 2 3 4 1
table[2]
2 3 4 5 2
Initialization of Multiple Dimension
Arrays
char board[3][3] = {‘X’,‘X’,‘O’,‘O’,‘X’, ‘O’,‘X’,‘O’,‘X’};
Thus, this declaration will set
board[0][0] to ‘X’,
board[0][1] to ‘X’,
board[0][2] to ‘O’,
board[1][0] to ‘O’,
board[1][1] to ‘X’,
board[1][2] to ‘O’,
board[2][0] to ‘X’,
board[2][1] to ‘O’,
board[2][2] to ‘X’.
Multi-dimensional ARRAYS
int daytab[2][13] = {
{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31} };
Note initialization of arrays within an array.
How to access an individual element
daytab[1][4] /* 2 nd row 5th element ie30*/
NOTE – the following is wrong!
daytab[1,4] /* wrong! */
Storing the marks of all students in all
subjects in a two- dimensional array
( subject no.)
[0] [1] [2] [3]
Highest 80