ConstReferenceImpliesImmutability
If a const variable refers to an object, that object is immutable.
An object referred to by a const variable is an immutable object
An object referred to by a const variable can be a mutable object
CorrectionHere is what's right.
Having a constant reference to an object or an array does not mean that that object or array is immutabile. The state of the object or the array can change: it is the variable that cannot.
Consider this example in which we declare a constant reference to an array and then change its second element. This is perfectly fine.
Using const
prevents changes to the variable itself, like we are attempting to do in the next example in which we reassign a
to a different array.
SymptomsHow do you know your students might have this misconception?
Watch a real student who might have this misconception solving a programming exercise!