Arrays
- Read the constraints before choosing an approach. Consider empty input and boundary cases early.
- If compilation reports
control reaches end of non-void function, make sure every reachable control path returns a value. A return inside one branch might leave another path uncovered. - When comparing values, check whether equality satisfies the condition.
- In C++, prefer
++i when the old value is unnecessary. Post-increment may have to preserve the previous value, particularly for user-defined types. - Use the correct type for Java floating-point literals.
float f = 1.1; // Invalid: 1.1 is a double literal in Java.
float f = 1.1f; // Valid.
double d = 34.4; // Valid.