Two-dimensional array




We have already studied about n-element one-dimensional array, which is same as a list of element. Similarly an m*n, two- dimensional array is same as a table of values which have m rows and n columns.

(For more visual clear display please click on the above format)
Syntax: data_type array_name[row_size] [column-size];

Example: int x[5] [5];
This example define a table as integer array having 5 rows and 5 columns.

I explain a two dimensional array in below:

int x[3][4]={1,2,3,4,5,6,7,8,9,10,11,12};

Hence x can be thought as a table contains 3 rows and 4 columns.

x[0] [0]=1 x[0][1]=2 x[0][2]=3 x[0][3]=4
x[1] [0]=5 x[1][1]=6 x[1][2]=7 x[1][3]=8
x[2] [0]=9 x[2][1]=10 x[2][2]=11 x[2][3]=12

No comments:

Post a Comment