The GATE Grind

GATE 2014 CS (CS2) – Question 44

Compiler Design · Intermediate Code Generation · 2 marks · Multiple choice

A compiler generates this for C access X[i][j][k], with 32-bit int and 8-bit char:

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

Which declaration is correct?

  1. int X[32][32][8];
  2. int X[4][1024][32];
  3. char X[4][32][8];
  4. char X[32][16][2];

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (A) int X[32][32][8];

Explanation

The kstride is4bytes, identifying int elements. The jstride32bytes means8elements in the final dimension. The istride1024bytes means32rows of32bytes each. Therefore **int X[32][32][8],A** matches the available declarations; the first dimension is selected from the listed choices.