1

I want to change a char in array of char at a specific position, I tried to assign an pointer to char to the array and dereference it to assign another value but it emit the signal SIGSEGV. it is normal ? Here is a conceptual code :

int main(){
    char * hello = "Hello";
    char * ptr = hello;
    *(ptr + 1) = 'c'; //trying to change 'e' to 'c'
}

Thank you and have a nice day.;)

Tiklyt
  • 63
  • 8
  • 6
    This string is in fact a *string literal*, which should not be modified (that is should be regarded as read-only), or it will cause undefined behavior. Try replacing `char * hello =..` with `char hello[] =...` – Eugene Sh. Oct 08 '21 at 17:00
  • 1
    Thank you for your comment, it is working now, I will check out the string literal concept :) – Tiklyt Oct 08 '21 at 17:03

0 Answers0