Page 309 - Computer science 868 Class 12
P. 309
b. Column Major System:
Address of A [ I ][ J ] Column Major Wise = B + W * [( I - Lr ) + M * ( J - Lc )]
1
5
9
2
6
10 Arranged I column major wise
3
7
11
4
8
12
Where,
B = Base address
I = Row subscript of an element whose address is to be found
J = Column subscript of an element whose address is to be found
W = Storage Size of one element stored in the array (in byte)
Lr = Lower limit of row/start row index of the matrix, if not given assume 0 (zero)
Lc = Lower limit of column/start column index of the matrix, if not given assume 0 (zero)
M = Number of rows of the given matrix
N = Number of columns of the given matrix
Note: Normally number of rows and columns of a matrix are given (like A[20][30] or A[40][60]) but if it
is given as A[Lr- – – – – Ur, Lc- – – – – Uc].
In this case number of rows and columns are calculated using the following methods:
Number of rows (M) will be calculated as = (Ur - Lr) + 1
Number of columns (N) will be calculated as = (Uc - Lc) + 1
And rest of the process will remain the same as per requirement (Row Major Wise or Column Major Wise).
1. An array X [-15……….10, 15……………40] requires one byte of storage. If the beginning location is 1500 determine
the location of X [15][20].
Ans. As you see here, the number of rows and columns is not given in the question. So they are calculated as:
Number or rows say M = (Ur - Lr) + 1 = [10 - (- 15)] +1 = 26
Number or columns say N = (Uc - Lc) + 1 = [40 - 15)] +1 = 26
(i) Column Major Wise Calculation of the above equation
The given values are: B = 1500, W = 1 byte, I = 15, J = 20, Lr = -15, Lc = 15, M = 26
Address of A [ I ][ J ] = B + W * [ ( I - Lr ) + M * ( J - Lc ) ]
= 1500 + 1 * [(15 - (-15)) + 26 * (20 - 15)]
= 1500 + 1 * [30 + 26 * 5]
307
Arrays 307

