The computer keeps track of Base (A), the address of the first element
A[0][0] of A[M][N], and computes address Loc (A[J][K]) of A[M][N] using the formula
Column–Major Order:
Loc (A[J][K] ) = Base (A) + W [M x K + J ]
OR
ROW MAJOR ORDER:
Loc (A [J][K]) = Base (A) + W [N x J + K ]
W denotes the size, i.e; number of bytes per data element of the array A, M is total numbers of rows, and N is total number of columns in the array.
thx for post...
ReplyDeleteRow Major Order:-
ReplyDeleteBase Address + Element Size[no. of column(i-lower bound of row)+(j-lower bound of column)]
Column Major Order:-
Base Address + Element Size[no. of row(j-lower bound of column)+(i-lower bound of row)]
The above formula is for INDIAN Schools.Smarter Formula is the one posted- the formula internationally accepted and accepted by java certificaters.
Deletehttp://www.javaforschool.com/625348-memory-address-calculation-in-an-array/
ReplyDelete