strrchr

Why strrchr() returns `char*` instead of `const char*`?

白昼怎懂夜的黑 提交于 2019-12-07 02:21:53
问题 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

STRCHR vs STRRCHR difference? [closed]

我只是一个虾纸丫 提交于 2019-12-01 22:54:39
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I would like to know the difference between the two different uses. I believe the difference in some what very subtle. This is an