The GATE Grind

GATE 2024 CS (CS2) – Question 43

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

Consider the expression $x[i]=(p+r)*-s[i]+u/w$. The triples are: (0) + p r; (1) ?; (2) uminus (1); (3) ?; (4) / u w; (5) + (3) (4); (6) ?; (7) = (6) (5). Which one of the following options fills in the missing entries CORRECTLY?

  1. (1) =[] s i, (3) * (0) (2), (6) []= x i
  2. (1) []= s i, (3) - (0) (2), (6) =[] x (5)
  3. (1) =[] s i, (3) * (0) (2), (6) []= x (5)
  4. (1) []= s i, (3) - (0) (2), (6) =[] x i

Practise this question in The GATE Grind →

Show answer and explanation

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

Explanation

(1) reads s[i] via =[] s i; (2) negates it; (3) multiplies (p+r) by the negation: * (0) (2). (6) forms the array element address x[i] via []= x i, which (7) then assigns to.