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

2002

Consider the following declaration of a two-dimensional array in C: char a[100][100]; Assuming that main memory is byte-addressable and that the array starts at memory address 0, the address of a[40][50] is:

  1. A.

    4040

  2. B.

    4050

  3. C.

    5040

  4. D.

    5050

Attempted by 14 students.

Show answer & explanation

Correct answer: B

C stores two-dimensional arrays in row-major order. For char a[100][100], each element occupies 1 byte, and each row contains 100 elements. The address of a[i][j] is Base + (i * number_of_columns + j) * element_size. Here, Base = 0, i = 40, j = 50, number_of_columns = 100, and element_size = 1 byte. Therefore, address = 0 + (40 * 100 + 50) * 1 = 4050.

Explore the full course: Gate Guidance By Sanchit Sir