English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

In two dimensional array X(7,9) each element occupies 2 bytes of memory.If the address of first element X(1,1)is 1258 then what will be the address of the element X(5,8) ?

2007-02-01 05:37:14 · 2 answers · asked by santosh 1 in Science & Mathematics Mathematics

2 answers

You can think of X as a matrix with 7 rows and 9 columns, which means it has a total of 63 numbers in it. Each of those 63 numbers occupies 2 bytes of memory, which the first number in locations 1258 and 1259, the second number in locations 1260 and 1261, etc.

The location of a specific entry depends on how the language compiler organizes arrays in memory, but usually you have all of the first row, followed by all of the second row, and so on, so I'll assume that's how this is working.

X(5,8) is the 8th entry of the 5th row, so it's preceded by 4 whole rows and the first 7 entries of the 5th row; that (4*9)+7 = 43 entries. Since each of those entries occupies 2 bytes, that means X(5,8) is 2*43 = 86 bytes beyond the start of the array. 1258 + 86 = 1344, so that would be considered the address of X(5,8) -- even though it actually occupies locations 1344 and 1345.

If by chance the entries of the array are instead stored column by column, then X(5,8) would be preceded by 7 whole columns plus the first 4 entries of column 8, which would be (7 * 7) + 4 = 53 entries. They would occupy 2 * 53 = 106 bytes, so X(5,8) would be at location 1258 + 106 = 1364.

2007-02-03 07:25:27 · answer #1 · answered by Jim R 3 · 0 0

1280
(5,8) is 11 units away from (1,1) - either 4 along, 7 down or vice-versa (across or down first doesn't affect the memory location though). So 11 * 2 bytes = 22; 1258 + 22 = 1280

2007-02-01 13:47:39 · answer #2 · answered by Kirstin 2 · 0 0

fedest.com, questions and answers