Created
July 7, 2015 05:37
-
-
Save andyli/b4107c8910208fe54764 to your computer and use it in GitHub Desktop.
const char * a is NOT a pointer to immutable char
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
#include<iostream> | |
using namespace std; | |
int main(int argc, char** argv) { | |
char c = 'a'; | |
const char * a = &c; | |
// *a = 'b'; // error: read-only variable is not assignable | |
cout << *a << endl; //a | |
c = 'b'; | |
cout << *a << endl; //b | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment