深拷貝和淺拷貝
阿新 • • 發佈:2017-09-15
深拷貝 淺拷貝
#include <stdio.h> int main(int argc, char *argv[]) { char *p1="123"; char *p2="123"; char *p3="456"; const char *p4="abc"; const char *p5="abc"; const char *p6="def"; printf("p1地址:%x\n",p1); printf("p2地址:%x\n",p2); printf("p3地址:%x\n",p3); printf("p4地址:%x\n",p4); printf("p5地址:%x\n",p5); printf("p6地址:%x\n",p6); char *a="windows"; char *b="123"; printf("a地址:%x\n",a); printf("b地址:%x\n",b); b=a; printf("b=a後:\n"); printf("a地址:%x\n",a); printf("b地址:%x\n",b); printf("a的內容:"); puts(a); printf("b的內容:"); puts(b); char str[80]="win10"; char *p=str; printf("str地址:%x\n",str); printf("p地址:%x\n",p); printf("str的內容:"); puts(str); printf("p的內容:"); puts(p); str[3]=‘x‘; printf("str[3]=‘x‘後:\n"); printf("str地址:%x\n",str); printf("p地址:%x\n",p); printf("str的內容:"); puts(str); printf("p的內容:"); puts(p); return 0; }
本文出自 “10628473” 博客,請務必保留此出處http://10638473.blog.51cto.com/10628473/1965425
深拷貝和淺拷貝