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) ?
1.1460 2.1365 3. 1356 4.1370

2007-10-01 06:34:11 · 5 answers · asked by magz 1 in Science & Mathematics Mathematics

5 answers

It depends on whether the array is stored in row-major or column-major form.

X is 7 rows by 9 columns.
X(5,8) is 4 rows and 7 columns ahead of X(1,1)

1258 + 2*(4*7 + 7) = 1328 (column major)
next address is 1329
1258 + 2*(7*7 + 4) = 1364 (row major)
next address is 1364

Looks like the second choice is the right one.

2007-10-01 07:07:18 · answer #1 · answered by PMP 5 · 0 0

Your question implies that that the lower bound of each index is 1,
so we are talking about a homogeneous array of 63 elements (each occupying 2 bytes of memory).

The answer depends somewhat upon the language and the implementation (and, sometimes, even the processor). Some store arrays in row order:
X(1,1), followed by X(2,1), X(3,1), ..., X(7,1), then X(1,2),X(2,2),X(3,2) ...
while others store in column order:
X(1,1), X(1,2), X(1,3), ....X(1,9), then X(2,1),X(2,2), X(2,3) ...
while some guarantee no semantics regarding storage, some pad with "green words" (e.g. to round up to a word-size or boundary), and some are processor dependent.

If we assume row order, then the element X(5,1) is the first element on the 5th row and it occurs after 4 full rows of 9 (2-byte) elements each, or 72 bytes beyond X(1,1).
Then (assuming no green word padding, processor quirks, etc), the address of X(5,1) would be:
= 1258 + 4*9*2
= 1258 + 72
= 1330
Now, X(5, 8) appears SEVEN elements later (not eight), which adds 14 bytes to the address: 1344

Since that is not one of your multiple-guess choices, let's try column order: element X(1,8) occurs after 7 full columns of 7 elements each (at 2-bytes per pop), which means that its address is:
1258 + 7*7*2
= 1258 + 98
= 1356
Then, skipping over four elements, to go from X(1,8) to X(5,8) we have:
1356 + 4*2
=1364

That's not one of your choices, either.
Try checking my arithmetic; maybe I added or counted or multiplied wrong (in my head). If not, I don't know what else to tell you.

----

The whole array occupies only 126 bytes, so 1460 is ridiculous.

1356 is a trap -- it's the address of the first element of the column, in column order. 1370 is what you get when you add 14 to it, which is skipping over 7 elements -- but you're looking for X(5,8) not X(8,8).

Ordinarily, I would eliminate the odd address (choice 3).
However, on small-endian architectures, the more-significant byte occurs at the higher address, so that might add 1 to the address you are looking for. It's tempting take the column-order address and add 1 to it, to get the high-order byte -- but that's NOT how addresses are used (even on little-endian machines), and I doubt the question was intended that way.

.

2007-10-01 07:21:51 · answer #2 · answered by bam 4 · 0 0

9 elements to a row

5 -> in 5th row, so 4 rows before:
4x9 = 36 entries before.
8 -> offset of 7 elements
36 + 7 = 43 element shift

43 X 2 = 86 bytes

I'm assuming 1258 is the address in bytes?
86 + 1258 = 1344

Don't know why that isn't an option there. In the implementation of the array, is there memory added for the end of rows?

2007-10-01 07:10:15 · answer #3 · answered by Leltos 5 · 0 0

Assuming X(1,2) is stored at decimal 1260 and x(1,3) is stored at decimal 1262, then X(5,8) will be the 4*9+8 = 44th element. So it should be stored at address
1258 + 43*2= 1344.

None of your answers seems correct.

2007-10-01 07:10:43 · answer #4 · answered by ironduke8159 7 · 0 0

O Sikander, O Sikander O Sikander, Jhaank Le Jhaank Le Apne Dil Ke Andar from Corporate

2016-05-18 01:45:07 · answer #5 · answered by ? 3 · 0 0

fedest.com, questions and answers