Partners: KDAB and Whole Tomato Software

22 June 2012

Const Correctness in C++


Memorize, memorize, memorize!!!


// value being pointed cannot be changed:
const char * ptr;


// address of the pointer cannot be changed, 
// but the value being pointed can be
char * const ptr;


// both value and the address of the pointer cannot be changed
const char * const ptr;

Those rules seem to be simple, but I sometimes forgot about them ;(

More info:



sign image taken from: http://openclipart.org/detail/3130/warning-notification-by-eastshores

Interested in new blog posts and bonus content? Sign up for my newsletter.

© 2017, Bartlomiej Filipek, Blogger platform
Any opinions expressed herein are in no way representative of those of my employers.
This site contains ads or referral links, which provide me with a commission. Thank you for your understanding.