fork download
  1. int main() {
  2. const char constant = 'A';
  3.  
  4. /* Pointer itself is modifiable, referenced value is immutable */
  5. const char *ptr1 = &constant;
  6. *ptr1 = 'B';
  7.  
  8. /* Pointer itself is immutable, referenced value is modifiable */
  9. char * const ptr2 = &constant;
  10. *ptr2 = 'C';
  11.  
  12. /* Alternate form for case 2 */
  13. typedef char* PChar;
  14. const PChar ptr3 = &constant;
  15. *ptr3 = 'D';
  16.  
  17. return 0;
  18. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
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*’
stdout
Standard output is empty