Why strrchr() returns `char*` instead of `const char*`?
问题 The function char* strrchr(const char *str, int ch) returns a pointer ( char* ) within str ( const char * ) where the last occurrence of ch is located. So we can write the following code without any cast: #include <string.h> int main() { const char CONSTSTR[] = "foo/bar/foobar.txt"; char *ptr = strrchr (CONSTSTR, '/'); *ptr++ = 'B'; *ptr++ = 'A'; *ptr++ = 'D'; } What is the advantage to return char* instead of const char* ? EDIT: As a Shafik Yaghmour pointed out, there are very good answers