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

Let a 2 - D array declaration be char Arr[100][100] store data such that the base address of the array is 0. Additionally, considering the array to be byte addrassable, what would be the address of element stored at arr[20][30].

Open in App
Solution

We know : 2D arrays are stored by default in Row-major order in C-programming language.
A[i][j] = base address + [(i - start index) × n + (j - start index)] × s.
Where,
m = no. of rows,
n = no of columns,
S = memory size,
Given, base address = 0,
start index = 0, s = 1,
arr [100][100] = a[m][n] arr[0 .... 99][0 ..... 99]
m = 100, n = 100
Arr[20][30] = 0 + [(20 - 0) × 100 + (30 - 0)] × 1
= 2000 + 30
Arr[20][30] = 2030.

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