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

Explain the difference between abstract class and interface in c++?

730


Explain what data encapsulation is in c++?

771


Do you know what are pure virtual functions?

850


Is swift a good first language?

778


Evaluate as true or false: !(1 &&0 || !1) a) True b) False c) Invalid statement

837


what is the difference between linear list linked representaion and linked representation? what is the purpose of representing the linear list in linked represention ? is it not avoiding rules of linear represention?

1971


Write a program to find the Factorial of a number

788


What are the important differences between c++ and java?

825


Explain rtti.

783


Explain the register storage classes in c++.

882


When does the c++ compiler create temporary variables?

800


What do you know about near, far and huge pointer?

790


Does a derived class inherit or doesn't inherit?

822


What does scope resolution operator do?

791


How much maximum can you allocate in a single call to malloc()?

848