For a C program accessing X[i][j][k], the following intermediate code is…

2014

For a C program accessing X[i][j][k], the following intermediate code is generated by a compiler. Assume that the size of an integer is 32 bits and the size of a character is 8 bits.

t0 = i ∗ 1024
t1 = j ∗ 32
t2 = k ∗ 4
t3 = t1 + t0
t4 = t3 + t2
t5 = X[t4]

Which one of the following statements about the source code for the C program is CORRECT?

  1. A.

    X is declared as “int X[32][32][8]”.

  2. B.

    X is declared as “int X[4][1024][32]”.

  3. C.

    X is declared as “char X[4][32][8]”.

  4. D.

    X is declared as “char X[32][16][2]”

Attempted by 44 students.

Show answer & explanation

Correct answer: A

Key insight: the multipliers t0, t1, t2 are byte offsets that reveal the element size and array dimensions.

  • From t2 = k * 4, each element is 4 bytes → element type is int (32 bits).

  • From t1 = j * 32 and element size 4: dim3 * 4 = 32 ⇒ dim3 = 8.

  • From t0 = i * 1024 and dim3 = 8: dim2 * dim3 * 4 = 1024 ⇒ dim2 = 1024 / (8 * 4) = 32.

Therefore the correct declaration is int X[32][32][8].

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…