Optimizing tips for C++
Few tips in C++ to optimize the code: --> Data Types: 1. Using of 'int' instead of char or short. Its good to use the data type 'int' instead of 'char' or 'short' wherever possible. Explanation: Data type 'int' is always the native type for the machine. --> Operators 1. Arithmetic operations. Addition is always faster than multiplication and multiplication is faster than division. And bit wise operations are faster than any other Operation. Where ever possible see if you can write the optimized code. This optimized code, will save a lot of time and system resources. 2. Use 'op='. Wherever possible, use 'op=' in favour of 'op'. For example, use myShape += value; rather than myShape = myShape + value; Explanation: The first version is better than the second because it avoids creating a temporary object. 3. if-else. Every 'if' should have corresponding 'else' . Eg: if(a>b) { someth...