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.c: In function ‘main’: prog.c:6: error: assignment of read-only location ‘*ptr1’ prog.c:9: warning: initialization discards qualifiers from pointer target type prog.c:14: warning: initialization discards qualifiers from pointer target type
Standard output is empty
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!