hello,
I was playing around with char pointers. I wanted to increment each letter of a char array by 1 character. i.e. 'hello' becomes 'ifmmp' (i = h+1)and here is a small code i wrote :
char *rushil = "hello";
while(*rushil != '\0')
{
++(*rushil); // run time error in this line dev C++ crashes
rushil++;
}
i am not sure but the program hangs on the line ++(*rushil).
I also tried :
You can't change it, because string literals are constant as wolfgang already said (that means they can be in memory sections that are read-only).
Conversion to a pointer to non-const char is only allowed for compatibility reasons and your compiler should warn you about it ("warning: deprecated conversion from string constant to ‘char*’"). Trying to modify the string results in undefined behavior.