Let A be a two-dimensional array declared as follows: A: array[1..110][1..125] of integer; Assuming that each integer takes one memory location, the array is stored in row-major order and the first element of the array is stored at the location. Find out the address of the address of the element A[i][j].
Answers
Answered by
0
Answer:
Explanation:
A two dimensional Array A is the collection of 'm X n' elements. Programming language stores the two dimensional array in one dimensional memory in either of two ways -
1) Row Major Order:
First row of the array occupies the first set of memory locations reserved for the array; Second row occupies the next set, and so forth.
To determine element address A[i,j]:
Location ( A[ i,j ] ) =Base Address + ( N x ( I - 1 ) ) + ( j - 1 )
For example :
Given an array [1…5,1…7] of integers. Calculate address of element T[4,6], where BA=900.
Solution:- I = 4 , J = 6 ,M= 5 , N= 7
Location (T [4,6]) = BA + (7 x (4-1)) + (6-1)
= 900+ (7 x 3) +5
= 900+ 21 + 5
= 926
Similar questions