浅拷贝和深拷贝问题
#include <stdio.h> int main(int argc, char *argv[]) { int x = 2; int y = x; int* p1 = &x; int* p2 = p1; printf("只拷贝值,不拷贝地址\n"); printf("深拷贝:x = %p,value = %d\n",&x,x); printf("深拷贝:y = %p,value = %d\n",&y,y); printf("只拷贝地址,不拷贝值\n"); printf("浅拷贝:p1 = %p,value = %d\n",p1,*p1); printf("浅拷贝:p2 = %p,value = %d\n",p2,*p2); return 0; } /* ---------- 运行c ---------- 只拷贝值,不拷贝地址 深拷贝:x = 0060FEF4,value = 2 深拷贝:y = 0060FEF0,value = 2 只拷贝地址,不拷贝值 浅拷贝:p1 = 0060FEF4,value = 2 浅拷贝:p2 = 0060FEF4,value = 2 输出完成 (耗时 0 秒) - 正常终止 */