Skip to content

Instantly share code, notes, and snippets.

@StevenJL
Last active May 24, 2017 07:59
Show Gist options
  • Save StevenJL/2899948025b42463ed63bc7b29381a8d to your computer and use it in GitHub Desktop.
Save StevenJL/2899948025b42463ed63bc7b29381a8d to your computer and use it in GitHub Desktop.
c_notes/pointers/const
char my_char = 'X';
char another_char = 'Y';
char * const char_fixed_ref = &my_char;
// char_fixed_ref should always point to my_char
char_fixed_ref = &another_char;
// this would raise a compiler error
const char *char_pointer_fixed_value = &my_char;
// my_char cannot change through the pointer char_pointer_fixed_value
*char_pointer_fixed_value = 'Z';
// this would raise compiler error
my_char = 'Z';
// you must reference the variable directly to change it
const char * const *char_pointer_fixed
// both the reference and value of this pointer is fixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment