The const qualifier does mainly two things:And what does const really do, i mean what is it really other that making something constant? What does it allow me to do?
1. It is a promise (not more than that) to the compiler that you will not modify the value. You can still cast the const away and modify the value anyway, but the compiler will assume that you keep your promise and might make optimizations based this, so cheating is unwise.
2. It allows you to bind a reference to a temporary, and extends the lifetime of that temporary to the lifetime of the const reference. Otherwise, if you were allowed to bind to a temporary (say, returning a local variable by reference) then whatever you alias does not exist any more by the time you use it, which is bad mojo. You would be reading and possibly modifying some more or less arbitrary data on the stack which might be overwritten by or overwrite other structures without your knowledge. Bad situation.
The newer C++11 rvalue references do a somewhat similar thing as in (2.), they allow you to "scavenge" a temporary by reference, omitting a copy. This works due to the fact that the temporary would die immediately after the return statement anyway. Thus, since it's already certain that the temporary is gone, nobody will notice that it's "missing", so another object can "steal" it with not side effects.