James Lockhart
James Lockhart

Reputation: 141

find location from base address

So my computer science professor decided to ask us a question but gave no instruction on how to find the answer. The question is as follow:

Compute the location of the following elements, where the base address is FFFFFBACD: A[4][6], A[5][5], A[2][7] The array is declared as int [][]= new int [8][10]

He isn't asking us to program anything but just find the location. The issue I have is that the base address looks off and I have no idea how to do the calculation to find the answer. Any guidance would be greatly appreciated!!

Upvotes: 0

Views: 1683

Answers (1)

Ori Lentz
Ori Lentz

Reputation: 3688

Assuming your integers are 4 bytes each, then element [0][0] is at address FFFFFBACD.

The next element is [0][1] in a distance of 4 bytes, meaning: FFFFFBAD1.

Overall in each "row" you have 10 elements, thus 40 bytes. Therefore the address for [1][0] is FFFFFBACD + 40 bytes = FFFFFBAF5

Therefore, [4][6] will be 40*4 + 5*4 bytes from the start address: FFFFFBB85.

(note that here the number of rows is 4 and multiplies 40 bytes per row and the number of elements in the fifth row is 6 and each is 4 bytes long - these are different reasons for multiplying by 4).

Using this logic, try and find the other addresses. It shouldn't be that hard.

Upvotes: 3

Related Questions