Determine the memory address for the following element using row-major order. Show the math.
Given, the base address of the array is 1200.
The array is 9 rows, 12 columns.
Element size is 4.
What is the memory address of Array[9,11]?
for data structure class
Solution:
Given,
=>Base address = 1200
=>Number of rows = 9
=>Number of columns = 12
=>Size of each element = 4 bytes
=>Row-major order is used.
Explanation:
Calculating address of Array[9, 11]:
=>Address of an element Array[i, j] = base address + size of element*(i*number of rows + j*number of columns)
=>Address of Array[9, 11] = 1200 + 4*(9*9 + 11*12)
=>Address of Array[9, 11] = 1200 + 4*(81 + 132)
=>Address of Array[9, 11] = 1200 + 4*(213)
=>Address of Array[9, 11] = 1200 + 852
=>Address of Array[9, 11] = 2052
=>Hence memory address of Array[9, 11] = 2052.
I have explained each and every part with the help of statements attached to it.
Get Answers For Free
Most questions answered within 1 hours.