Skip to content

Instantly share code, notes, and snippets.

@peterflynn
Created September 16, 2015 20:36
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterflynn/7644af3d72b3aba20a96 to your computer and use it in GitHub Desktop.
Save peterflynn/7644af3d72b3aba20a96 to your computer and use it in GitHub Desktop.
C++ Pointer Syntax Cheatsheet
// If "const" is to the LEFT of "*" it applies to the object being pointed at
// If "const" is to the RIGHT of "*" it applies to the variable holding the pointer address
const T* ptr; // object is immutable
T const* ptr; // "
T* const ptr; // 'ptr' cannot be changed to point to a different address, but object is not immutable
// (i.e. the variable is const, not the thing it points to)
const T* const ptr; // object is immutable AND 'ptr' cannot be changed to point to a different address
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment