Let A be a two dimensional array declared as follows: A: array [1 ... 10] [1…

1998

Let A be a two dimensional array declared as follows:

A: array [1 ... 10] [1 ... 15] of integer;

Assuming that each integer takes one memory location, the array is stored in row-major order and the first element of the array is stored at location 100, what is the address of the element a[i][j] ?

Answer: A. 15i + j + 84ConceptFor a two-dimensional array A[L1:U1][L2:U2] stored in row-major order, with base address B and element size s, the address of A[i][j] is found by…

  1. A.

    15i + j + 84

  2. B.

    15j + i + 84

  3. C.

    10i + j + 89

  4. D.

    10j + i + 89

Attempted by 177 students.

Show answer & explanation

Correct answer: A

Concept

For a two-dimensional array A[L1:U1][L2:U2] stored in row-major order, with base address B and element size s, the address of A[i][j] is found by counting how many elements come before it: each complete row holds (U2 − L2 + 1) elements, so reaching row i means skipping (i − L1) full rows, then advancing (j − L2) more positions within row i. This gives Address = B + [(i − L1) × (number of columns) + (j − L2)] × s.

Application

Here L1 = 1, U1 = 10, L2 = 1, U2 = 15, base B = 100, and element size s = 1 (each integer occupies one memory location):

  1. Number of columns = U2 − L2 + 1 = 15 − 1 + 1 = 15.

  2. Substitute into the formula: Address = 100 + [(i − 1) × 15 + (j − 1)] × 1.

  3. Expand the bracket: (i − 1) × 15 = 15i − 15, and (j − 1) = j − 1.

  4. Combine: Address = 100 + 15i − 15 + j − 1 = 15i + j + 84.

Address of A[i][j] = 15i + j + 84.

Cross-check

Test the formula against the given fact that the first element is at location 100. The first element is A[1][1] (i = 1, j = 1): substituting gives 15(1) + 1 + 84 = 100, exactly the stated base address, confirming the formula is set up correctly.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Iocl Engineers Officers Grade A Paper 2

Loading lesson…