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

Is c++ a low level language?

916


What is an html tag?

1077


Can I learn c++ as my first language?

1053


How can you quickly find the number of elements stored in a dynamic array? Why is it difficult to store linked list in an array?

984


Why we use #include conio h in c++?

992


What is std namespace in c++?

1117


What is the oldest programming language?

948


What is a terminating character in c++?

1321


Explain the uses of static class data?

1053


Difference between a homogeneous and a heterogeneous container

1090


How do you add an element to a set in c++?

934


What c++ is used for?

1011


Should you pass exceptions by value or by reference?

1087


What is an overflow error?

1048


Can member data be public?

992