Skip to content

Instantly share code, notes, and snippets.

@welll
Created December 14, 2014 01:39
Show Gist options
  • Save welll/10da89ae01c8a13dc140 to your computer and use it in GitHub Desktop.
Save welll/10da89ae01c8a13dc140 to your computer and use it in GitHub Desktop.
C++ - Const
void Foo( int * ptr,
int const * ptrToConst,
int * const constPtr,
int const * const constPtrToConst )
{
*ptr = 0; // OK: modifies the "pointee" data
ptr = NULL; // OK: modifies the pointer
*ptrToConst = 0; // Error! Cannot modify the "pointee" data
ptrToConst = NULL; // OK: modifies the pointer
*constPtr = 0; // OK: modifies the "pointee" data
constPtr = NULL; // Error! Cannot modify the pointer
*constPtrToConst = 0; // Error! Cannot modify the "pointee" data
constPtrToConst = NULL; // Error! Cannot modify the pointer
}
//http://cdecl.ridiculousfish.com/?q=char+*%28%26x%29%28int%2Culong%29%3B
//http://www.unixwiz.net/techtips/reading-cdecl.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment