#define  _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

/*
深拷贝: 拷贝方和被拷贝方不共享一片内存
浅拷贝: 拷贝方和被拷贝方共享一片内存
*/
typedef struct Stu {

int len;
char *ps;
}stu;
int main(int args , char * argv []) {

stu sa, sb;
sa.ps = (char *)malloc(sizeof(char )*10);
strcpy(sa.ps,"hello");
printf("sa.ps=%s\n",sa.ps);
sb.ps = (char *)malloc(sizeof(char) * 10);
//sb.ps = sa.ps; --浅copy
strcpy(sb.ps , sa.ps); //--深copy
printf("sb.ps=%s\n",sb.ps);
*sa.ps = 'Z';
printf("%s\n",sb.ps);
getchar();
return 0;
}




编程是一种快乐,享受代码带给我的乐趣!!!