若有以下程序 #include #include #include typedefstructstu{ char*name,gender; intscore; }STU; voidf(char*p) { p=(char*)malloc(10); strcp

admin2015-07-31  13

问题 若有以下程序
#include
#include
#include
typedefstructstu{
char*name,gender;
intscore;
}STU;
voidf(char*p)
{
p=(char*)malloc(10);
strcpy(p,"Qian");
}
main()
{
STUa={NULL,’m’,290},b;
a.name=(char*)malloc(10);
strcpy(a.name,"Zhao");
b=a;
f(b.name);
b.gender=’f’;b.score=350;
printf("%s,%c,%d,",a.name,a.gender,a.score);
printf("%s,%c,%d\n",b.name,b.gender,b.score);
}
则程序的输出结果是

选项 A、Zhao,m,290,Qian,f,350
B、Zhao,m,290,Zhao,f,350
C、Qian,f,350,Qian,f,350
D、Qian,m,290,Qian,f,350

答案B

解析 本题考查结构体变量中的引用,其中a的name为Zhao,b执行函数f(b.name)后b的name并没有改变,还是Zhao,所以答案为B选项。
转载请注明原文地址:https://kaotiyun.com/show/kBDp777K
0

最新回复(0)