int main() { const char constant = 'A'; /* Pointer itself is modifiable, referenced value is immutable */ const char *ptr1 = &constant; *ptr1 = 'B'; /* Pointer itself is immutable, referenced value is modifiable */ char * const ptr2 = &constant; *ptr2 = 'C'; /* Alternate form for case 2 */ typedef char* PChar; const PChar ptr3 = &constant; *ptr3 = 'D'; return 0;}
Standard input is empty
prog.cpp: In function ‘int main()’: prog.cpp:6: error: assignment of read-only location ‘* ptr1’ prog.cpp:9: error: invalid conversion from ‘const char*’ to ‘char*’ prog.cpp:14: error: invalid conversion from ‘const char*’ to ‘char*’
Standard output is empty
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!