A friend told me that it’s more efficient to do
int addNumbers(const int number1, const int number2);
than
int addNumbers(int number1, int number2);
assuming of course that number1 and number2 won’t be assigned new values. Does this result in a significant performance boost? Are there any other side effects I should know about?
const correctnessis more of letting compiler help you guard against making honest mistakes. Declaring the const-ness of a parameter is just another form of type safety rather than a boost for performance.Most of the modern compiler will be able to detect if a variable is really constant or not, and apply correct optimizations. So do not use const-correctness for performance reasons. rather use it for maintainability reasons & preventing yourself from doing stupid mistakes.