Isn't “const” redundant when passing by value?

The const also prevents code inside the function from modifying the parameter itself. When a function is larger than trivial size, such an assurance helps you to quickly read and understand a function. If you know that the value of side won't change, then you don't have to worry about keeping track of its value over time as you read.

Under some circumstances, this might even help the compiler generate better code.

The const also prevents code inside the function from modifying the parameter itself. When a function is larger than trivial size, such an assurance helps you to quickly read and understand a function. If you know that the value of side won't change, then you don't have to worry about keeping track of its value over time as you read.

Under some circumstances, this might even help the compiler generate better code. A non-trivial number of people do this as a matter of course, considering it generally good style.

Makes sense. Thanks. – DanielS Jan 3 at 15:10 Why "also"?

That's all it does. – Keith Thompson Jan 3 at 18:12 @KeithThompson -- indeed, that's all it does, but the O.P. is thinking of const ref parameters, where the const keeps you from changing the original object. – Ernest Friedman-ll Jan 3 at 18:49.

You can do something like this: int f(int x) { x = 3; //with "const int x" it would be forbidden // now x doesn't have initial value // which can be misleading in big functions }.

2 +1 for illustrating :) – Matthieu M. Jan 3 at 15:17.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions