有以下程序 #include #include typedef struct { char name[9]; char sex; float score[2]; } STU; void f(STU a) { STU b={"Zhao", ’m’, 8

admin2015-07-28  22

问题 有以下程序
#include
#include
typedef struct { char name[9]; char sex; float score[2]; } STU;
void 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;
}
main()
{
STU c={"Qian", ’f’, 95.0, 92.0};
f(c);
printf("%s,%c,%2.0f,%2.0f\n", c.name, c.sex, c.score[0], c.score[1]);
}
程序的运行结果是( )。

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

答案A

解析 函数f()传递的参数为结构体变量,也是一种值传参,形参的变化不能影响到实参,所以调用函数f(c)对c中的数据没有影响。所以输出结果为选项A)。
转载请注明原文地址:https://kaotiyun.com/show/I7Jp777K
0

随机试题
最新回复(0)