GateAI
Intermediate Code Generation

GATE CSE 2024 Set 2 · Q43

MCQ2 marksMedium

Time

Consider the following expression: x[i]=(p+r)∗−s[i]+u/wx[i] = (p + r) * -s[i] + u/w. The following sequence shows the list of triples representing the given expression, with entries missing for triples (1), (3), and (6). Which one of the following options fills in the missing entries CORRECTLY?

GATE CSE 2024 Set 2 Q43 diagram

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) (1) =[] s i (3) * (0) (2) (6) []= x i

Intermediate Code Generation

In three-address code represented via triples, each entry has three fields: (op, arg1, arg2), and intermediate values are referenced by their triple indices (such as (0), (1), etc.).

Let us break down the evaluation of the expression x[i]=(p+r)∗−s[i]+u/wx[i] = (p + r) * -s[i] + u/w step-by-step:

  1. Triple (0): Evaluates p+rp + r

    (0)+pr(0) \quad + \quad p \quad r
  2. Triple (1): Array access / dereference for s[i]s[i] (reading an array element into a temporary value uses the operator =[]):

    (1)=[]si(1) \quad =[] \quad s \quad i
  3. Triple (2): Computes unary minus of s[i]s[i]:

    (2)uminus(1)(2) \quad \text{uminus} \quad (1)
  4. Triple (3): Multiplies (p+r)(p + r) with −s[i]-s[i], which corresponds to multiplying the result of triple (0) with triple (2):

    (3)∗(0)(2)(3) \quad * \quad (0) \quad (2)
  5. Triple (4): Computes u/wu / w:

    (4)/uw(4) \quad / \quad u \quad w
  6. Triple (5): Adds the two terms (p+r)∗−s[i](p + r) * -s[i] and u/wu / w:

    (5)+(3)(4)(5) \quad + \quad (3) \quad (4)
  7. Triple (6): Specifies the array target location x[i]x[i] for assignment (using the indexed assignment operator []=):

    (6)[]=xi(6) \quad []= \quad x \quad i
  8. Triple (7): Assigns the final expression value in (5) to the array location specified by (6):

    (7)=(6)(5)(7) \quad = \quad (6) \quad (5)

Thus, the missing entries are:

  • (1):=[] s i

  • (3):* (0) (2)

  • (6):[]= x i

This matches 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 Q43 of the GATE CSE 2024 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 2024 Set 2.

How GATE tests Intermediate Code Generation

More from GATE CSE 2024 Set 2

Share this solution

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

GateAI solution cardGATE CSE 2024 Set 2 · Q43 · MCQ

Consider the following expression: x[i] = (p + r) * -s[i] + u/w. The following sequence shows the list of triples representing the given expression, with entries missing for triples (1), (3), and (6). Which one of the following options fills in the missing entries CORRECTLY?

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.