O'Reilly logo

C++ FAQs, Second Edition by Mike Girou, Greg Lomow, Marshall Cline

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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& ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required