Which of the following code replacements is an example of operator strength reduction?
- Replace P^2 by P*P
- Replace P*16 by P<< 4
- Replace pow(P,3) by P*P*P
- 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.