Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 what are accessor methods?

1125


What is functions syntax in c++?

1145


What is a virtual destructor? Explain the use of it?

992


What are the advantages of using pointers in a program?

1142


What do you mean by public protected and private in c++?

1064


Explain what is oop?

1094


What is iostream in c++ used for?

1039


What is the outcome of cout< a) 16 b) 17 c) 16.5

1019


Is c++ a float?

1067


What are namespaces in c++?

1099


What sorting algorithm does c++ use?

1151


I want to write a C++ language program that: 1. Reads in the size of a square from the screen; 2. Prints a hollow square of that size out of “-“, “|” and blanks on screen; 3. Prints the same hollow square onto a text file. The program should work for squares of all side sizes between 1 and 20.

2797


Can we use pointers in c++?

1056


Write a program using shift_half( ) function to shift the elements of first half array to second half and vice versa.

1330


What is a float in c++?

987