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

Given a 2-D array A[-20 .... 10, 8 ..... 16] where the starting location is 20. Consider that the memory space occupied by the array is 4 bytes and stored is row-major order. What is the location of A[4][16]?

A
920
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
820
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
C
630
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
720
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is B 820
Given : range : [-20 .... 10][8 ..... 16]
location : A[4][16]
No. of rows (m) = 10 - (-20) + 1 = 31
No. of columns (n) = 15 - 8 + 1 = 8
New range : [0 ... 30][0 .... 7]
New location : A[4 - (-20)][16 - 8]
of A[4][16]
A[24][8]
A[0][0] = 20

Row major order
A[i][j] = B.A. + [j + i× n] × memory
we know B.A. = 20
A[24][8] = 20 + [8 + 24 × 8] × 4
= 20 + [8 + 192] × 4
= 20 + 200 × 4
A[24][8] = 820.

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