Sunday, November 2, 2014

4.1.3 TWO-DIMENSIONAL ARRAY

Def:

The two-dimensional array is generally called a matrix.

Horizontal arrangement of elements is called row and vertical arrangement of elements is called column.

Memory Layout:

The elements of all arrays are stored contiguously in increasing memory locations, essentially in a single list.


  
Declaration of two-dimensional arrays

General form:

            type   array_name[row_size] [column_size];

The type specifies the type of element that will be contained in the array, the row_size indicates the maximum number of rows of the matrix and column_size indicates the maximum number of columns in the matrix.

e.g.      int attd[50][30];

           

Initialization of two-dimensional array

§  Compile-time Initialization

e.g.      float     total[2][3] = { 0, 0, 0, 1, 1, 1};

 

§  Run-time Initialization

e.g.      int   num[10][10];

for ( i = 0; i <= 10; i++)
                        {
           for ( j = 0; j <= 10; j++)
            {
                        scanf ( “%d”, &num[i][j]);
                        }
            }

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.