I declared a pointer that pointed to an type of char array, and I changed one of the elements to '\0'. I think the function "strlen" can get the length for the first elements to the '\0' , but actually, the program crashed. Anybody knows the reason ?
Asked
Active
Viewed 69 times
1 Answers
0
Your character pointer points to a string literal, which is immutable data. For backwards compatibility reasons, the compiler allows a non-const char*
to point to the literal, but as you noticed, attempting to modify the string crashed the program.

Sebastian Redl
- 69,373
- 8
- 123
- 157