在编译这个程序时,我会收到一个我从未想过的输出.当我审查这个程序时,我预计指针的结果仍然是"Hello,world!" 因为据我所知指针从来没有受到指针2.然而,我的输出显示,当指针打印包含指针2的字符串'Y你们!’.怎么会这样?谢谢!!
#include <stdio.h>
#include <string.h>
int main() {
char str_a[20];
char *pointer;
char *pointer2;
strcpy(str_a, "Hello, world!\n");
pointer = str_a;
printf(pointer);
pointer2 = pointer + 2;
printf(pointer2);
strcpy(pointer2, "y you guys!\n");
printf(pointer);
}
Run Code Online (Sandbox Code Playgroud)
产量
Hello, world!
llo, world!
Hey you guys!
Run Code Online (Sandbox Code Playgroud)