For a 2-D array represented in row-major order, the index formula to access…
2025
For a 2-D array represented in row-major order, the index formula to access the element at row “i” and column “j” using the base address “B” is:
- A.
Index = B + (i * n + j) / Index = B + (i* n + j)
- B.
Index = B + (j n + i) / Index = B + (j n + i)
- C.
Index = B + (i + j) / Index = B + (i + j)
- D.
Index = B + (i m + j) / Index = B + (i m + j)
Attempted by 634 students.
Show answer & explanation
Correct answer: A
In row-major order, a 2-D array is stored row by row in contiguous memory. To find the index of an element at row i and column j, we need to calculate the offset from the base address B. Step 1: Each row has n columns, so the total number of elements in i full rows is i × n. Step 2: Within row i, the element at column j is at position j from the start of the row. Step 3: The total offset from the base address is (i × n + j). Step 4: Therefore, the index of the element is: Index = B + (i × n + j).