Skip to content

Instantly share code, notes, and snippets.

@andyli
Created July 7, 2015 05:37
Show Gist options
  • Save andyli/b4107c8910208fe54764 to your computer and use it in GitHub Desktop.
Save andyli/b4107c8910208fe54764 to your computer and use it in GitHub Desktop.
const char * a is NOT a pointer to immutable char
#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