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 do the header files usually contains?

768


What is the array and initializing arrays in c++?

671


Are strings immutable in c++?

831


Why #include is used?

754


What is a set in c++?

671






Mention the ways in which parameterized can be invoked. Give an example of each.

738


Is c++ a low level language?

646


Which software is used to run c++ program?

671


What is data binding in c++?

661


How the programmer of a class should decide whether to declare member function or a friend function?

826


What is encapsulation in c++?

844


Show the declaration for a static member variable.

669


What is command line arguments in C++? What are its uses? Where we have to use this?

792


How can I learn dev c++ programming?

725


What is friend class in c++ with example?

637