Skip to content
Official PYQ · 2002

GATE CS 2002 Q2.8 — Programming in C

Explain with AI

Consider the following declaration of a two-dimensional array in C:

char a[100][100]a[100][100];

Assuming that the main memory is byte-addressable and that the array is stored starting from memory address 00, the address of a[40][50]a [40][50] is:

Choose one option
View worked solution

Answer: B

In C, two-dimensional arrays are stored in row-major order. This means elements are stored row by row in contiguous memory locations.

For a 2D array declared as char a[M][N], the memory address of the element at index [i][j] is calculated using the formula:

Address(a[i][j])=Base Address+(i×N+j)×sizeof(element)\text{Address}(a[i][j]) = \text{Base Address} + (i \times N + j) \times \text{sizeof}(\text{element})

Given the following values from the question:

  • Array declaration: char a[100][100], so the number of columns N=100N = 100.
  • Base Address = 00
  • Target element: a[40][50], so i=40i = 40 and j=50j = 50.
  • Since the array is of type char, the size of each element is 11 byte (under standard byte-addressable memory).

Substituting these values into the formula:

Address(a[40][50])=0+(40×100+50)×1\text{Address}(a[40][50]) = 0 + (40 \times 100 + 50) \times 1

Address(a[40][50])=4000+50=4050\text{Address}(a[40][50]) = 4000 + 50 = 4050

Therefore, the address of a[40][50] is 4050.

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

Published
Report a correction
Keep exploringMore Programming in C questions