我很难理解pointer2
包含什么.第二个printf
打印llo World
,但第三个打印Hey you guys!
.如果strcpy
把y you guys!\n
复制成llo World
,为什么会是这样呢.根据我对下面程序的理解,最后的输出应该是llo Worldy you guys!\n
,不是吗?
int main()
{
char str_a[20]; // a 20 element character array
char *pointer; // a pointer, meant for a character array
char *pointer2; // and yet another one
strcpy(str_a, "Hello World\n");
pointer = str_a; // set the first pointer to the start of the array
printf("%p\n", pointer);
pointer2 = pointer + 2; // set the second one 2 bytes further in
printf("%s", pointer2); // print it
strcpy(pointer2, "y you guys!\n"); // copy into that spot
printf("%s", pointer); // print again
}