Machine-translated by Google. Questions are authored in English.
Top

Discussion

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).

(0)+pr
(1)
(2)uminus(1)
(3)
(4)/uw
(5)+(3)(4)
(6)
(7)=(6)(5)

Which one of the following options fills in the missing entries CORRECTLY?

  • A.(1) =[] s i; (3) * (0) (2); (6) []= x i
  • B.(1) []= s i; (3) - (0) (2); (6) =[] x (5)
  • C.(1) =[] s i; (3) * (0) (2); (6) []= x (5)
  • D.(1) []= s i; (3) - (0) (2); (6) =[] x i

Answer: A

The missing triples are (1) =[] s i, (3) * (0) (2), (6) []= x i.

Triple (2) applies uminus to the result of (1), and the expression negates \(s[i]\), so (1) must fetch the array element: =[] s i (an indexed read). The product \((p + r) * -s[i]\) multiplies the results of (0) and (2), so (3) is * (0) (2), and (5) then adds \(u/w\) from (4).

The target \(x[i]\) is an indexed location, so (6) is []= x i (an indexed write), and (7) assigns the value from (5) to it.

Options with - in (3) subtract where the expression multiplies, and options with []= in (1) write to s instead of reading it. Putting (5) in triple (6) is wrong because the index of x is i; the value (5) is supplied by triple (7).

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.