fork(1) 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.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
stdout
Standard output is empty