#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 ",sa.ps); sb.ps = (char *)malloc(sizeof(char) * 10); //sb.ps = sa.ps; --浅copy strcpy(sb.ps , sa.ps); //--深copy printf("sb.ps=%s ",sb.ps); *sa.ps = 'Z'; printf("%s ",sb.ps); getchar(); return 0; }