Foo* const ptr ptr is a const pointer to a Foo Object. The Foo object can be changed using the pointer ptr, but you can’t change the pointer ptr itself.
const Foo* ptr ptr points to a Foo object that is const. The Foo object can’t be changed via ptr.
const Foo* const ptr ptr is a const pointer to a const Foo object. Neiher can the pointer ptr be changed, nor can you change the Foo object using ptr.
Reading the declaration right to left is a easy way to remember what they mean.
Difference between Foo* const ptr, const Foo* ptr, const Foo
Foo* const ptr ptr is a const pointer to a Foo Object. The Foo object can be changed using the pointer ptr, but you can’t change the pointer ptr itself.
const Foo* ptr ptr points to a Foo object that is const. The Foo object can’t be changed via ptr.
const Foo* const ptr ptr is a const pointer to a const Foo object. Neiher can the pointer ptr be changed, nor can you change the Foo object using ptr.
Reading the declaration right to left is a easy way to remember what they mean.