Give 2 examples of a code optimization?

Answer Posted / maria

1) For checking modulo use

num1&(num2-1)

instead:

num1%num2

2) For multiplying or dividing by 2 use left and right shift
accordingly.

3) In loop use, if code allows it, decrement,like this:
for(int i = MAX_VALUE ; i > 0 ; i--)
instead:
for(int i = 0 ; i < MAX_VALUE; i++)

Is This Answer Correct ?    7 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is an incomplete type in c++?

762


Difference between overloaded functions and overridden functions

576


How are pointers type-cast?

639


Write a corrected statement in c++ so that the statement will work properly. if (4 < x < 11) y=2*x;

1499


How do I get good at c++ programming?

593






Is java the same as c++?

543


what does the following statement mean? int (*a)[4]

617


Explain abstraction.

614


What is heap sort in c++?

596


What is the protected keyword used for?

614


What is vector string in c++?

570


Why iomanip is used in c++?

632


What is a pointer with example?

658


How do you traverse a btree in backward in-order?

619


What is the difference between delegation and implemented-in-terms-of?

517