Last active
May 24, 2017 07:59
-
-
Save StevenJL/2899948025b42463ed63bc7b29381a8d to your computer and use it in GitHub Desktop.
c_notes/pointers/const
This file contains hidden or 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
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