This code is giving me a segmentation fault at run time.
char *str = "HELLO";
str[0] = str[2];
Please can anyone tell me why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Standard does not allow modifying a string literal. The string is stored in a readonly segment of the program, for example in linux, it is stored in the
.rodatasection of the executable which cannot be written.