2,040 views

3 Answers

1 votes
1 votes

Array VAL is stored row wise starting from location 1500. Each element requires 4B.

VAL[1][1] is stored at 1500

First, we'll store 1st row 1st column, then 1st row 2nd column, and so on until all elements of 1st row are stored. Then similarly, we store 2nd row, 3rd row and so on -

VAL[1][2] is stored at 1500 + (0 * 10 + 1) * 4 = 1504

VAL[1][9] is stored at 1500 + (0 * 10 + 8) * 4 = 1532

VAL[2][1] is stored at 1500 + (1 * 10 + 0) * 4 = 1540

VAL[12][1] is stored at 1500 + (11 * 10 + 0) * 4 = 1940

VAL[12][9] is stored at 1500 + (11 * 10 + 8) * 4 = 1972

Answer - Location of VAL[12][9] is 1972. 

1 votes
1 votes
base address = b =1500

stored in row major order and each element is of 4 bytes

hence, w = 4 bytes

location of any array element in row major order is given by formula

loc(A[i][j]) = Base Address + w * (relative index of element)

i.e.,

loc(A[i][j]) = Base Address + w * [(i-LBi)*n +(j-LBj)]

here,

         ‘n’ is the number of columns = UBj – LBj +1 = 10 – 1 + 1 = 10

loc(VAL[12][9]) = 1500 + 4*[(12-1)*10 + (9-1)]

loc(VAL[12][9]) = 1972
0 votes
0 votes
2D Array RMO with Base Address =0

Formula to Calculate it

A [i] [j] = [(i-1)*n+j-1]*size of each element+Base address

Now,

Val [12] [9]= [(12-1)*10+9-1]*4+1500]

Related questions

2 votes
2 votes
1 answer
1
Beyonder asked Dec 20, 2017
2,074 views
Consider a lower triangular Matrix A[-25....+25, -25....+25], base address (BA)=0, size of element = 100 Byte. Find the location of a [-20][-21] (Ordering: Row Major)?
2 votes
2 votes
2 answers
2
set2018 asked Aug 11, 2017
521 views
2 votes
2 votes
4 answers
3
iarnav asked May 8, 2017
2,521 views
char * a[] = "red shoes";How the space in string constant "red shoes" will be stored in 1-D array in memory?
5 votes
5 votes
6 answers
4
Pankaj Joshi asked Jan 26, 2017
15,864 views
Consider 3 dimensional Array A[90] [30] [40] stored in linear array in column major order. If the base address starts at 10. The location of A[20] [20] [30] is __________...