有下列程序: #include <stdio.h> #include <string.h> typedef struct{ char name[9];char sex;float score[2]; }STU; STU f(STU a) { STU b={

admin2018-10-16  25

问题 有下列程序:
#include <stdio.h>
#include <string.h>
typedef struct{ char name[9];char sex;float score[2]; }STU;
STU f(STU a)
{ STU b={"Zhao",’m’,85.0,90.0};int i;
strcpy(a.name,b.name);
a.sex=b.sex;
for(i=0;i<2;i+ +) a.score=b.score;
return a;
}
main( )
{ STU c={"Qian",’f’,95.0,92.0},d;
d=f(c); printf("%s,%c,%2.0f,%2.0f\n",d.neme,d.sex,d.score[0],d.score[1]);
}
程序的运行结果是

选项 A、Qian,m,85,90
B、Zhao,f,95,92
C、Zhao,m,85,90
D、Qian,f,95,92

答案D

解析 f( )函数的功能是对形参a的各个成员用结构体变量b的各个成员进行赋值后,然后返回变量a。在主函数中调用f(c )函数时,将STU类型的结构体变量c的值传递给形参a,函数f( )在对a的各个成员进行重新赋值后,再将返回变量a的值传给d,最后输出结构变量d的各个成员的值。
转载请注明原文地址:https://kaotiyun.com/show/dwxp777K
0

随机试题
最新回复(0)