But surely the value at the memory of itsAge could also be changed if the function were not constant? |
No. That is incorrect.
You get back a COPY of the value. This is known as pass-by-value; what gets passed in/out is not the actual object, but a COPY of the value. Contrast this with pass-by-reference (look it up when you have a moment; it's quite important).
So
getAge returns a COPY of the value
itsAge. This is a copy of an integer. You can do whatever you like to it, and you will not affect the actual value of
itsage inside the object.
getName returns a COPY of the pointer
itsName. You can do whatever you like to that copy (as the pointer isn't constant, it's a pointer
to a constant), but if you dereference the copy, you'll be able to access the
original stored character array
inside the object. Clearly, whoever wrote this does not want you to be able to directly change those stored characters.
It is a way of ensuring that if you want to change the stored values inside the object, you have to use the functions provided and cannot just reach in there and change things yourself.
If pointers are not as easy for you as integers yet, please read this:
http://www.cplusplus.com/articles/EN3hAqkS/
Other pointer articles exist too - I just like this one :p