C Programming language

adplus-dvertising
Program to add two 2-D array and place the result in the third array
Previous Home Next

Mainly multidimensional arrays are stored  in the memory in the following two ways :

  1. Row-Major order Implementation
  2. Column-Major order Implementation

 In Row-Major Implementation of the arrays, the arrays are stored in the memory in terms of the row design, i.e. first the first row of the array is stored in the memory then second and so on. Suppose we have an array named arr having 3 rows and 3 columns then it can be stored in the memory in the following manner :

int arr[3][3];

  arr[0][0] arr[0][1] arr[0][2]
  arr[1][0] arr[1][1] arr[1][2]
  arr[2][0] arr[2][1] arr[2][2]

Thus an array of 3*3 can be declared as follows :

arr[3][3] = { 1, 2, 3,

              4, 5, 6,

              7, 8, 9 };

and it will be represented in the memory with row major implementation as follows :

   1   2   3   4   5     6   7   8   9


In Column-Major Implementation of the arrays, the arrays are stored in the memory in the term of the column design, i.e. the first column of the array is stored in the memory then the second and so on. By taking above eg. we can show it as follows :

arr[3][3] = { 1, 2, 3,

              4, 5, 6,

              7, 8, 9 };

and it will be represented in the memory with column major implementation as follows :

   1   4   7   2   5     8   3   6   9