GateAI
Intermediate Code Generation

GATE CSE 2014 Set 2 · Q34

MCQ2 marksEasy

Time

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 * 1024t1 = j * 32t2 = k * 4t3 = t1 + t0t4 = t3 + t2t5 = X[t4] Which one of the following statements about the source code for the C program is CORRECT?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) X is declared as " int X[32][32][8] ".

Intermediate Code Generation

In C, multidimensional arrays are stored in row-major order. For a 3D array declaration T X[D1][D2][D3] where the element size is SS bytes:

Offset of X[i][j][k]=((i×D2+j)×D3+k)×S\text{Offset of } X[i][j][k] = ((i \times D2 + j) \times D3 + k) \times S
Offset=i×(D2×D3×S)+j×(D3×S)+k×S\text{Offset} = i \times (D2 \times D3 \times S) + j \times (D3 \times S) + k \times S

From the given intermediate code:

  • t2 = k * 4   ⟹  S=4 bytes=32 bits\implies S = 4\text{ bytes} = 32\text{ bits} (element type is int).

  • t1 = j * 32   ⟹  D3×S=32  ⟹  D3×4=32  ⟹  D3=8\implies D3 \times S = 32 \implies D3 \times 4 = 32 \implies D3 = 8.

  • t0 = i * 1024   ⟹  D2×D3×S=1024  ⟹  D2×32=1024  ⟹  D2=32\implies D2 \times D3 \times S = 1024 \implies D2 \times 32 = 1024 \implies D2 = 32.

Thus, the array elements are int, and the last two dimensions are [32][8][32][8]. Hence, X is declared as int X[32][32][8] (Option A).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Intermediate Code Generation previous year question is Q34 of the GATE CSE 2014 Set 2 paper. Find more GATE CSE PYQs on Intermediate Code Generation in Compiler Design, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Intermediate Code Generation PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Intermediate Code Generation in GATE CSE

Intermediate Code Generation has 14 GATE CSE PYQs across 12 papers from 2011 to 2025. 4 of them are 2-mark MCQs like this one, and it is the only one in GATE CSE 2014 Set 2.

How GATE tests Intermediate Code Generation

More from GATE CSE 2014 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2014 Set 2 · Q34 · MCQ

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?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.