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:

Get my free ebook about C++17!

More than 50 pages about the new Language Standard.

C++17 in detail, by Bartlomiej Filipek

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