Which language is this ?
You're initializing a char* using a const char* which is wrong by itself because it may cause the error you're going to get like that one.
In short, char* cannot be changed. It's a const.
Extending what Sahand said, in C char* ptr = <string-literal>; This gives you a pointer to a string literal which is not modifiable (it is in the text segment in asm generated which is read only). If you wish to modify the string use the literal to initialize an array char str[] = <string-literal>; Unlike the above case it'll create the array on stack using the literal. Which should allow you to modify the array
It's C, which shouldn't be surprising considering we are in a C/C++ group.
Sorry for being late. Anyways, It's C; I think you can tell from the void function parameter.
Really? But, let's be real, It's really confusing why const char *str can be changed.
Yeah, but why I can modify it although it's const char* as shown in the previous message.
You're assigning to a pointer to const data. The pointer itself is not const there. For example *message = is not possible.
Oh yeah. Now I figured it out. Thank y'all for helping.
I explained it didn'r i?
It is fully legal make a const ptr , point to another address. You just can't change the value of the content that it points to.
Yup, you're right. I get a segmentation fault when I tried to change a single character.
char* just like any other regular pointer can be changed.
Обсуждают сегодня