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

Can notepad ++ run c++?

0 Answers  


Show the application of a dynamic array with the help of an example.

0 Answers  


What do you mean by function and operator overloading in c++?

0 Answers  


What is string in c++ programming?

0 Answers  


Write a c++ code that will calculate the roots of a quadratic equation a2+ bx+c=0 Hint: d = sqrt (b2-4ac), and the roots are: x1 = (€“b + d)/2a and x2 = (€“b €“ d)/2a (use sqrt function from cmath.h )?

0 Answers   Maxobiz,






What is the output of the following 3D Array int arr[3][2][2]={1,2,3,4,5,6,7,8,9,10,11,12}; what is the output for arr[2][1][0]?

6 Answers   HCL, Integra, IPMC, ORG,


How does c++ sort work?

0 Answers  


What is null and void pointer?

0 Answers  


Given the following function definition: int doit(int &x, int y, int &z) { x = 3*x; y = y + 5; z = x+y; return z - 4; } int a = 5, b = 7, c = 9, d = 11; d = doit(a,b,c);

2 Answers  


What is linked list in c++?

0 Answers  


Where Malloc(), Calloc(), and realloc() does get memory?

0 Answers  


What is the difference between c++ and turbo c++?

0 Answers  


Categories