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) ?

clear steps plz....

2006-10-10 00:11:14 · 4 answers · asked by yamuna s 1 in Science & Mathematics Mathematics

4 answers

It depends on the implementation of array

Assuming decimal address

If in column major form
-----------------------------------

address of X(5, 8) = 1258 + (total no. of rows * last col - 1 + no. of rows in last col - 1) * size
= 1258 + (7 * (8 - 1) + (5 - 1)) * 2
= 1364

If in row major form
-----------------------------------
address of X(5, 8) = 1258 + (total no. of cols * last row - 1 + no. of cols in last row - 1) * size
= 1258 + (9 * (5 - 1) + (8 - 1)) * 2
= 1344

2006-10-10 00:42:18 · answer #1 · answered by fsm 3 · 0 0

mm I think it depends of the implementation

but one way would be to store elements this way


00000001111111 .... 88888888


that way the position of any element is given by assuming the first 0,0

x*7 + y;

now with first 1,1

(x-1)*7+(y-1)

now if each occupies 2 bytes the adddress would be:

2*[(x-1)*7+(y-1)]

and since it starts in 1258 and you want 5,8 but

the address would be 1258 + 2*(4*7 + 7);

1258+70

1328 IMHO : )

2006-10-10 07:32:06 · answer #2 · answered by Kilimanjaro 4 · 0 0

5-1=4 rows before 5th row , 4*9=36 :we have 9 element in every row.
8-1=7culumns before 8th .
answer :(36+7)*2+1258

2006-10-10 07:32:32 · answer #3 · answered by hadi 1 · 0 0

1,1 coorresponds to 1258
so 5,8 is 40*2bytes futher , the rest of this u can do urself

btw why do u wanna know this ?

2006-10-10 07:23:53 · answer #4 · answered by gjmb1960 7 · 0 0

fedest.com, questions and answers