for(int n = 0; n < size; ++n)
sum += elements [n];
Leaving aside the stylistic question of declaring variables in the middle of a for statement, and trusting that the author knows that the variable sum will never overflow and (if he's dealing with floating-point values) that rounding errors won't matter, the code should still be for(size_t n = 0; n < size; ++n)
sum += elements [n];
An index to an array should always be declared as size_t, not as int. Otherwise really bad things can happen on systems where size_t is 64 bits but int is 32 bits.EDIT: Before someone accuses me of being overly pedantic: I've lost count of how many security issues I've fixed which have existed because someone used int where they meant size_t, but it's at least in the double-digits.