Give 2 examples of a code optimization?

Answers were Sorted based on User's Feedback



Give 2 examples of a code optimization?..

Answer / mms zubeir

I would like to quote two things from the same area.

1. Read/Write chunks from/into a file instead of byte by
byte reading.

2. Aquire resources late and relieve it early. Example, if
you want to use a file, open the file as late as possible
and release it as early as possible after use.

Is This Answer Correct ?    12 Yes 1 No

Give 2 examples of a code optimization?..

Answer / maria

http://en.wikipedia.org/wiki/Modulo_operation

Is This Answer Correct ?    1 Yes 0 No

Give 2 examples of a code optimization?..

Answer / 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

Give 2 examples of a code optimization?..

Answer / sudheer

How this num1&(num2-1) replaces num1%num2. Execute and
check before posting some thing...

Is This Answer Correct ?    1 Yes 4 No

Post New Answer

More C++ General Interview Questions

what are Operators and explain with an example?

0 Answers  


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

0 Answers  


What is a static element?

0 Answers  


Brief explaination about #include<iostream.h>, cin and cout

3 Answers  


what are the iterator and generic algorithms.

0 Answers  






Can I make ios apps with c++?

0 Answers  


If you hear the cpu fan is running and the monitor power is still on, but you did not see anything show up in the monitor screen. What would you do to find out what is going wrong?

0 Answers  


How do you define a class in c++?

0 Answers  


What are the 2 main types of data structures?

0 Answers  


What are different types of polymorphism supported by C++

2 Answers   CA, GameLoft,


what is difference between static and non-static variables

10 Answers  


What is c++ code?

0 Answers  


Categories