Skip to content
Official PYQ · 1998

GATE CS 1998 Q2.14 — Arrays, Stacks and Queues

Explain with AI

Let AA 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 100100, what is the address of the element A[i][j]A[i][j]?

Choose one option
View worked solution

Answer: A

To find the memory address of the element A[i][j]A[i][j] in a 2D array stored in row-major order, we use the standard address calculation formula.

1. Given Parameters

  • Array Declaration: A[1extto10][1extto15]A[1 ext{ to } 10][1 ext{ to } 15]
  • Number of rows (RR): 1010
  • Number of columns (CC): 1515
  • Lower bound of row index (L1L_1): 11
  • Lower bound of column index (L2L_2): 11
  • Base Address (BABA): 100100
  • Size of each element (WW): 11 memory location

2. Row-Major Address Formula

In row-major order, elements are stored row by row. To reach the element A[i][j]A[i][j], we must skip (i−L1)(i - L_1) complete rows (each containing CC elements) and then skip (j−L2)(j - L_2) elements in the current row.

Address(A[i][j])=BA+[(i−L1)×C+(j−L2)]×W\text{Address}(A[i][j]) = BA + \left[ (i - L_1) \times C + (j - L_2) \right] \times W

3. Calculation

Substitute the given values into the formula:

Address(A[i][j])=100+[(i−1)×15+(j−1)]×1\text{Address}(A[i][j]) = 100 + \left[ (i - 1) \times 15 + (j - 1) \right] \times 1 Address(A[i][j])=100+15i−15+j−1\text{Address}(A[i][j]) = 100 + 15i - 15 + j - 1 Address(A[i][j])=15i+j+84\text{Address}(A[i][j]) = 15i + j + 84

Thus, the correct option is A.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Arrays, Stacks and Queues questions