IAE Academy

GATE 2024 CS2 Q.43: solution and answer

GATE 2024 · CS2Q.43 · 2 marks · MCQ

Consider the following expression: . 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 2024 CS2 question 43: A table of eight triples (0) to (7), each with an operator and two operands.Tap to open full size
Figure from the GATE 2024 CS2 paper. It is part of the question.
Figure description

A table of eight triples (0) to (7), each with an operator and two operands. (0): +, p, r. (1): blank, blank, blank. (2): uminus, (1), blank. (3): blank, blank, blank. (4): /, u, w. (5): +, (3), (4). (6): blank, blank, blank. (7): =, (6), (5). Gray watermark text reading GATE2024 lies across the image.

  1. (A)

    (1) =[] s i; (3) * (0) (2); (6) []= x i

  2. (B)

    (1) []= s i; (3) - (0) (2); (6) =[] x (5)

  3. (C)

    (1) =[] s i; (3) * (0) (2); (6) []= x (5)

  4. (D)

    (1) []= s i; (3) - (0) (2); (6) =[] x i

Answer and solution

ANSWER

Option (A): (1) =[] s i; (3) * (0) (2); (6) []= x i.

Official answer: ASource: Official answer key, GATE 2024 CS2 (IISc Bengaluru)

  1. Apply precedence: unary minus binds tightest, then * and /, then +, then =. The right-hand side is , assigned to .

  2. Triple (0) is + p r, which gives . This is the left operand of *.

  3. Triple (1) must fetch the value of (an array element read, or rvalue). In triple notation an array read is =[] s i, so (1) is =[] s i. Triple (2), uminus (1), then negates it to give .

  4. Triple (3) must combine the two operands of *, namely (triple (0)) and (triple (2)). So (3) is * (0) (2). It is a multiplication, not a subtraction, so options B and D are wrong.

  5. Triples (4) and (5) compute and then add it to (3). This matches the printed table, which confirms (3) is the product.

  6. Triple (7) is = (6) (5), an assignment of the value (5) to the location named by (6). So (6) must be the store target . In triple notation an array store is []= x i, with operands and . Triple (7) then supplies the value, so (6) does not take (5) as an operand. This rules out options B and C, whose (6) uses (5) or =[].

  7. Combining the three entries: (1) =[] s i, (3) * (0) (2), (6) []= x i. This is option A.

KEY IDEA

In triples, reading an array element is =[] a i. Storing into one is []= a i, followed by a separate = (that triple) value triple. The operator in (3) comes from the expression: * for the product of and .

WATCH OUT FOR

Swapping =[] (read) with []= (store), or giving the store triple the value (5) as its operand when the assignment triple (7) already carries it. Also reading the * between and as a minus sign because of the unary minus.

From the GATE 2024 CS2 paper. Every question of this paper · Download the full paper · All 2 Intermediate code questions, with notes