What is 2D Array? Difference between Row-Major and Column-Major Array.

2D Array:

             Collection of rows and columns known as 2D Array or a multidimensional Array.

             The first index selects the row and the second index select the column within that row.

syntax:  

             data type Array name [Rows][columns];

For example:

             int a[4][3]

Row-Major Column-Major
1. Value passed in row that is known as row-major. 1. Value passed in column that is known as column-major.

2. For example

   int a[4][2];

 

 

2. For example

   int a [4][2];

 

3. In this example value passed as a one by one row first pass the value in a[0][0] then a[0][1] up to a[3][1] in one by one row. 3. In this example  value passed as a one by one column first pass the value in a[0][0] then a[1][0], a [2][0] up to a[3][1] in one column to another column.

4. int a[4][2];

   for(i=0; i<=3; i++)

   {

        for(j=0; j<=1; j++)

        {

         scanf("%d",&a[i][j];

        }

   }

4. int a[4][2];

   for(i=0; i<=1; i++)

   {

      for(j=0; j<=3; j++)

       {

         scanf("%d",&a[j][i]);

       }

    }



Average Rating (0)
by krishna   chaudhari  in C Language  on 7/19/2015 5:09:29 AM  


Post Your Comment
*