C/C++深度copy和浅copy

#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 )*);
strcpy(sa.ps,"hello");
printf("sa.ps=%s\n",sa.ps);
sb.ps = (char *)malloc(sizeof(char) * );
//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 ;
}
上一篇:[IOS]swift自定义uicollectionviewcell


下一篇:php 图片上传 500 Internal Server Error 错误