Created
December 14, 2014 01:39
-
-
Save welll/10da89ae01c8a13dc140 to your computer and use it in GitHub Desktop.
C++ - Const
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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