Computer Sciences > Gate 2024 Set-2 > Thread
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?
A
(1) =[]⁑⁑𝑠⁑⁑𝑖   (3) * (0) (2)   (6) []=⁑⁑π‘₯⁑⁑𝑖
B
(1) []=⁑⁑𝑠⁑⁑𝑖   (3) –⁑(0)⁑(2)   (6) =[] ⁑π‘₯⁑⁑(5)
C
(1) =[] ⁑𝑠⁑𝑖   (3) * (0)⁑⁑(2)   (6) []= ⁑π‘₯⁑⁑(5)
D
(1) []= ⁑𝑠⁑⁑𝑖   (3) –⁑(0)⁑(2)   (6) =[] π‘₯⁑⁑𝑖

Correct : c

Explanation:
To determine the missing elements, let's break down how three-address code triples represent array accesses and assignments. A triple consists of three fields: op (operator), arg1, and arg2. When referencing the result of a previous operation, the row number enclosed in parenthesesβ€”like (0)β€”is used.
1. Analyze Triple (1): Array Indexing of s[i]
β€’ The sub-expression is s[i].
β€’ In three-address code triples, an array access/r-value lookup uses the array base address and index. The operator is represented as =[].
β€’ Therefore, row (1) evaluates s[i]:
    (1) =[] s i
β€’ This eliminates options (b) and (d), which specify []= (used for array assignment/l-value, not lookup).
2. Analyze Triple (2): Unary Minus
β€’ Looking at the table, row (2) computes uminus (1), which represents -s[i]. This confirms our deduction for row (1) is correct.
3. Analyze Triple (3): Multiplication
β€’ The expression requires multiplying (p+r) by -s[i].
β€’ Row (0) computed + p r (which is p+r).
β€’ Row (2) computed -s[i].
β€’ Therefore, row (3) must perform the multiplication of row (0) and row (2):
    (3) * (0) (2)
4. Analyze Triples (4) and (5): Addition with u/w
β€’ Row (4) computes / u w (which is u/w).
β€’ Row (5) adds row (3) and row (4) together: + (3) (4). This represents the entire right-hand side of our assignment equation.
5. Analyze Triple (6): Target Array Location x[i]
β€’ The value calculated in row (5) needs to be stored into the left-hand side array position x[i].
β€’ Before a value can be assigned to an array element, we define its l-value location using the array base address and index with the element assignment operator []=.
β€’ Therefore, row (6) targets the x[i] element:
    (6) []= x i
6. Analyze Triple (7): Assignment
β€’ Row (7) shows = (6) (5), which copies the computed right-hand side expression from row (5) into the array destination specified in row (6).
7. Conclusion:
Matching our findings (1) =[] s i, (3) * (0) (2), and (6) []= x i directly corresponds to choice (c).

Similar Questions

Consider a multi-threaded program with two threads T1 and T2. The threads share two semaphores: s1 (initialized to 1) and s2 (initialized to 0). The threads a...
#842 MCQ
Consider an array X that contains n positive integers. A subarray of X is defined to be a sequence of array locations with consecutive indices. The C code...
#844 MCQ
Let 𝑀 be the 5-state NFA with πœ–-transitions shown in the diagram below. Which one of the following regular expressions represents the language accepted...
#845 MCQ

Related Topics

No tags found

Unique Visitor Count

Total Unique Visitors

Loading......