Recall that some languages (like Fortran) allow one to create two-dimmensional a
ID: 3713108 • Letter: R
Question
Recall that some languages (like Fortran) allow one to create two-dimmensional arrays. Consider the following array declaration in such a language.
double[ 1..10, 1..15 ] A;
Recall that a double takes up 8 bytes. Assume that the array is layed out in memory beginning at address 1000 and uses row major format. What is the adress of A[7,5]?
A) 1046
B) 1057
C) 1094
D) 1110
E) 1368
F) 1456
G) 1752
H) 1880
I) None of these
*PART B*
Now, suppose an array from the previous item is layed out using column major format at the same address. What is the address of A[7,5]?
A) 1046
B) 1057
C) 1094
D) 1110
E) 1368
F) 1456
G) 1752
H) 1880
I) None of these
*****PLEASE SHOW ALL OF YOUR WORK. IF YOU DO I WILL THUMB UP YOUR ANSWER*****
Explanation / Answer
A)
Row major format: Store the data row wise
A[1][1] ................................A[1][15]
1000 ...................................1112 (1000+15*row num * 8 -8 )
where 15 number of columns
we can subtract -8 because first element at 1000 remaining 2-15 require => 14 elements * 8 = 112
A[2][2] ................................A[2][15]
1020 ...................................1232 (1000+15*row num * 8 -8 ) =1232
A[6][15] = (15*6 * 8 -8) = 712
A[7][1] = 1720
A[7][2] = 1728
A[7][3] = 1736
A[7][4] = 1744
A[7][5] = 1752
Option G correct
B)
colon major format: Store the data column wise
A[1][1] ................................A[1][10]
1000 ...................................1072 (1000+10*column num * 8 -8 )
where 15 number of colons
we can subtract -8 because first element at 1000 remaining 2-10 require => 9 elements * 8 = 72
A[10][4] = (1000+10*column num * 8 -8 ) = 1312
A[1][5] = 1320
A[2][5] = 1328
A[3][5] = 1336
A[4][5] = 1344
A[5][5] = 1352
A[6][5] = 1360
A[7][5] = 1368
Option E correct
Please rate my answer
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.