Data Structures | Nielit Scentist-B [02-12-2018]

Which of the following code replacements is an example of operator strength reduction?

  1. Replace P^2 by P*P
  2. Replace P*16 by P<< 4
  3. Replace pow(P,3) by P*P*P
  4. Replace (P <<5) -P by P*3




Answer: B

Explanation:

In option (B), Multiplication operation is replaced with Shift Operator . It reduce the operator strength because shift operator is less expensive than multiplication operation.
Here, most suitable option is 2) Replace P × 16 by P ≪ 4

Practice unlimited  Gate CSE Questions

Do U have Better Solution?
Contribute your Solution in the Comment Section below.

GATE, ISRO, BARC, UGC-NET, NIELIT
Online Test Series available.

Leave a Reply