Intermediate Code
![Question 34, GATE 2014: A compiler accesses X[i][j][k] using byte-offset code t0=i*1024; t1=j*32; t2=k*4; t3=t1+t0; t4=t3+t2; t5=X[t4]. Integers are 32 bits, characters 8 bits. Which declaration matches? A int X[32][32][8]; B int X[4][1024][32]; C char X[4][32][8]; D char X[32][16][2].](../../assets/questions/CS-2014-S2-Q44-1.webp)
Answer & solution
Official answer: A
1. Set up the reasoning. For a row-major three-dimensional array with element size e and trailing dimensions d2,d3, the offset is e·(i·d2·d3+j·d3+k). Match its three coefficients to the generated code.
2. Derive the result. The byte strides show 4-byte int elements, 8 elements in the last dimension(32/4), and 32 in the middle dimension(1024/32). The first dimension is not recoverable from strides alone, but among the listed declarations only int X[32][32][8] matches. Thus A.
3. Check the interpretation. The innermost coefficient identifies e=4 bytes; j then gives d3=8 and i gives d2=32. The leading dimension is not encoded in these strides, so select the matching offered declaration without claiming that 32 as its first dimension was derived.