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

3- Write a program to find larger and smaller of the two numbers.

4 Answers   Luminous,


Can I make ios apps with c++?

0 Answers  


What are the differences between a struct in C and in C++?

8 Answers   Amazon, Wipro,


What is the difference between new/delete and malloc/free?

1 Answers  


What are pointer-to-members? Explain.

0 Answers   iNautix,






Difference between shift left and shift right?

1 Answers   Symphony,


What is an ABC: an "Abstract Base Class"?

1 Answers  


Is c++ faster than c?

0 Answers  


Who invented turbo c++?

0 Answers  


How new/delete differs from malloc()/free?

0 Answers  


Is c++ built on c?

0 Answers  


What does the nocreate and noreplace flag ensure when they are used for opening a file?

0 Answers  


Categories