fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. size_t strlen(const char *s){
  5. const char *sc;
  6. for(sc = s; *sc != '\0'; ++sc)
  7.  
  8. return (sc-s);
  9. }
  10.  
  11. void bad_func( const char * s)
  12. {
  13. const char * sc = s;
  14. *sc = 'a'; // error, modifying a const char through sc
  15.  
  16. // trying to subvert the const-ness with a non-const pointer will fail too
  17. char * s2 = s; // error, cannot convert const char* to char*;
  18. }
  19.  
  20. int main() {
  21. // your code goes here
  22. return 0;
  23. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘void bad_func(const char*)’:
prog.cpp:14:8: error: assignment of read-only location ‘* sc’
  *sc = 'a'; // error, modifying a const char through sc
        ^~~
prog.cpp:17:14: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
  char * s2 = s; // error, cannot convert const char* to char*;
              ^
stdout
Standard output is empty