Give 2 examples of a code optimization?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
How to tokenize a string in c++?
What gives the current position of the put pointer?
What is size_type?
What are the sizes and ranges of the basic c++ data types?
Explain how an exception handler is defined and invoked in a Program.
What are formatting flags in ios class?
What is c++ stringstream?
Why is c++ still used?
Explain how functions are classified in C++ ?
Write a code/algo to find the frequency of each element in an array?
why and when we can declar member fuction as a private in the class?
How to get the current position of the file pointer?