coding180 icon
Coding180

How to calculate the address of a random element in a two-dimensional array? Suppose the given base address is BA.

Home > Interviews > PHP


robort - 2022-10-03 01:31:11

Row-major order : If the array is declared as a[m][n]where m is the number of rows and n is the number of columns, the element address of the array stored in the row- a[i][j]major order is calculated as:

Address(a[i][j]) = B. A. + (i * n + j) * size

Column-major order : If the array is declared as a[m][n]where m is the number of rows and n is the number of columns, the addresses of the array elements stored in the column- a[i][j]major order are calculated as:

Address(a[i][j]) = ((j*m)+i)*Size + BA

user

Robort Gabriel

Lagos, Nigeria

Freelance Web Developer, Native Android Developer, and Coding Tutor.

Skills
  • UI / UX
  • JavaScript
  • Python
  • PHP
  • Kotlin
  • Java
  • Bootrap
  • Android
  • Laravel