Chapter 14. Const Correctness

FAQ 14.01 How should pointer declarations be read?

Pointer declarations should be read right to left.

If Fred is some type, then

Fred* is a pointer to a Fred (the * is pronounced “pointer to a”).

const Fred* is a pointer to a Fred that cannot be changed via that pointer.

Fred* const is a const pointer to a Fred. The Fred object can be changed via the pointer, but the pointer itself cannot be changed.

const Fred* const is a const pointer to a Fred that cannot be changed via that pointer.

References are similar: read them right to left.

Fred& is a reference to a Fred (the & is pronounced “reference to a”).

const Fred& is a reference to a Fred that cannot be changed via that reference.

Note that Fred& ...

Get C++ FAQs, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.