#include <stdio.h>
#include <string.h>
int main()
{
char s[10] = "hello";
printf("%s\n", strcpy(s, s + 1));
printf("%s\n", s);
return 0;
}
打印结果是:
ello
ello
这个我理解,把ello\0往前复制了。
#include <stdio.h>
#include <string.h>
int main()
{
char s[10] = "hello";
printf("%s\n", strcpy(s + 1, s));
printf("%s\n", s);
return 0;
}
打印结果却是:
helll
hhelll
这个hhelll我就不理解了。不应该是hhello吗
本来想试一下 strcpy 的行为,自己写个实现。但现在它的行为我不理解了。
vs2019 试的,需要按照 https://blog.csdn.net/oguro/article/details/52685662 添加宏才能运行。