Partners: KDAB Whole Tomato Software CppDepend

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

Get my free ebook about C++17!

More than 50 pages about the new Language Standard.

C++17 in detail, by Bartlomiej Filipek

For now I don't have my own courses, but I promote others :) (Please note, I'll also get a little commission for every signup. That's a huge support for my work!). Have a look my recommended Online Courses at @Pluralsight (more info in my Resource page):

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