English

Let Us Assume Data[20][15] is a Two-dimensional Array, Which is Stored in the Memory Along the Row with Each of Its Elements Occupying 2 Bytes. Find the Address of the Element Data(10][5], If the Element Data[10][L5] is Stored at the Memory Location 15000. - Computer Science (C++)

Advertisements
Advertisements

Question

Let us assume Data[20][15] is a two-dimensional array, which is stored in the memory along the row with each of its elements occupying 2 bytes. Find the address of the element Data(10][5], if the element Data[10][l5] is stored at the memory location 15000.

Solution

W - 2

N - 20

M - 15

Loc(Data[15][10]) = 15000

Row major formula:

Loc(Data[i][j]) = Base(Data) + W*(M * i + j)

Loc(Data[15][10]) = Base(Data) + 2*(15 * 15 + 10)

15000 = Base(Data) + 2*(225 + 10)

= Base(Data) + 2 * 235

= Base(Data) + 470

Base(Data) = 15000 – 470

= 14530

Loc(Data[10][5]) = 14530 + 2 * (15 * 10 + 5)

= 14530 + 2 * (150 + 5)

= 14530 + 2 * 155

= 14530 + 310

= 14840

shaalaa.com
  Is there an error in this question or solution?
2017-2018 (March) All India Set 4
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×