fork download
  1. #import <objc/objc.h>
  2. #import <objc/Object.h>
  3.  
  4. @interface TestObj
  5. @end
  6.  
  7. @implementation TestObj
  8. int main() {
  9. // your code goes here
  10. const char* test = "hello";
  11.  
  12. //compilation error:
  13. //test[2] = '1';
  14. //printf("%s", test);
  15.  
  16. //runtime error:
  17. //char* test2 = test;
  18. //test2[2] = '1';
  19. //printf("%s", test2);
  20.  
  21. //no error
  22. int len = strlen(test);
  23. char* copy = malloc(len + 1);
  24. strcpy(copy, test);
  25. copy[2] = '1';
  26. printf("%s", copy);
  27.  
  28. free(copy);
  29. return 0;
  30. }
  31. @end
Success #stdin #stdout 0.01s 10176KB
stdin
Standard input is empty
stdout
he1lo