CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
3
You visited us 3 times! Enjoying our articles? Unlock Full Access!
Question

Consider a 2 - D array A[m][n] where m are the number of rows and n are the number of columns. Assuming that each of the element takes 's' memory locations. The array A is stored in a row-major order, then the address of the element A[i][j] can be given as : (Assuming the location of 1st element as b and starting of the array index from 1)

A
[(ij)+j(i1)2]
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
b+(j1)×s+(i1)×s×n
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
C
b+(i1)×s+1(j1)×m×s
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
(ji)+[(ij)n(i1)(i2)2]
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is B b+(j1)×s+(i1)×s×n
The address of an element A[i][j] in row-major order is given as :
A[i][j] = Base (A) + (j - start index) × size of element) + (i - start index) × size of element × n
Here :
Base (A) = b
Size of element =S
Start index = 1
m : no of rows, n : no. of colums
we get A[i][j] = b + (j - 1) × s + (i - 1) × s × n

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
2D Arrays
OTHER
Watch in App
Join BYJU'S Learning Program
CrossIcon