Technical Interview Questions

The largest pool of technical questions with answers, explantions, code and detailed analysis

Archive for the ‘Technical Interview Questions’ Category

const Correctness: Difference between Foo* const ptr, const Foo* ptr, const Foo* const ptr

Posted by tekpool on January 10, 2007

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

Posted in C++, General, Microsoft, Progamming Languages, Technical Interview Questions | 10 Comments »