#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct stu{
char *name,gender;
int score;
};
main(){
struct stu a={NULL,'m',290},b;
a.name=(char *) malloc(10);
strcpy (a.name,"zhao");
b=a;
b.gender='f';
b.score=350;
strcpy(b.name,"qian");
printf("%s,%c,%d ",a.name,a.gender,a.score);
printf("%s,%c,%d",b.name,b.gender,b.score);
}
因为你进行的是内存拷贝,两种方式可看出差别:
1.值拷贝
2.在strcpy(b.name,"qian");前重新malloc
懂了,谢谢
你不自己断点看看到哪一步哪个值发生变化,光别人讲给你听是没用的,要学会自己找问题,学会程序调试很重要