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

How to declare a pointer to an array of integers?

729


What is meant by the term name mangling in c++?

608


What is a memory leak c++?

668


How do you declare A pointer to function which receives an int pointer and returns a float pointer

776


What is the difference between the functions rand(), random(), srand() and randomize()?

826






Is it possible to write a c++ template to check for a function's existence?

661


What is a static member?

692


What is the difference between an array and a list?

667


What is the use of setfill in c++?

677


What is the difference between global int and static int declaration?

503


Explain "const" reference arguments in function?

698


What are structs in c++?

676


What is the difference between an enumeration and a set of pre-processor # defines?

951


Why are pointers used?

653


How compile and run c++ program in turbo c++?

741