单选题有以下程序:#include #include typedef struct stu{ char name[10]; char gender; int score;}STU;void f(char *name,char gender,int score){ strcpy(name,Qian); gender='f'; score=350;}main(){ STU a={Zhao,'m',290},b; b=a; f(b.name,b.gender,b.score); printf(%s,%c,%d,

题目
单选题
有以下程序:#include #include typedef struct stu{ char name[10]; char gender; int score;}STU;void f(char *name,char gender,int score){ strcpy(name,Qian); gender='f'; score=350;}main(){ STU a={Zhao,'m',290},b; b=a; f(b.name,b.gender,b.score); printf(%s,%c,%d,, a.name, a.gender, a.score); printf(%s,%c,%d, b.name, b.gender, b.score);}程序的运行结果是(  )。
A

Zhao,m,290,Qian,m,290

B

Zhao,m,290,Zhao,m,290

C

Zhao,m,290,Qian,m,350

D

Zhao,m,290,Qian,f,350

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

有以下程序includeincludetypedef strtlct{char name[9];char sex;floatsc

有以下程序 #include <stdio.h> #include <string.h> typedef strtlct{ char name[9]; char sex;floatscore[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[i]=b

A.Qian,f,95,92

B.Qian,m,85,90

C.Zhao,f,95,92

D.Zhao,m,85,90


正确答案:A
解析: 本题考查的是函数调用时的参数传递问题。程序在调用函数f时,传给函数f的参数只是结构变量c在栈中的一个拷贝,函数f的所有操作只是针对这个数据拷贝进行的修改,这些都不会影响变量c的值。

第2题:

有以下程序

#include <stdio.h>

#include <string.h>

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[i]=b.score[i];

}

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在栈中的一个拷贝,函数f的所有操作只是针对这个数据拷贝进行的修改,这些都不会影响变量c的值。

第3题:

有以下程序

#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[i]=b.score[i];

return a;

}

main()

{ STU c={"Qian",'f',95.0,92.0},d;

d=f(c); printf("%s,%c,%2.0f,%2.0f\n",d.name,d.sex,d.score[0],d.score[1]);

}

程序的运行结果是

A)Qian,f,95,92

B)Qian,m,85,90

C)Zhao,m,85,90

D)Zhao,f,95,92


正确答案:C

第4题:

有以下程序 #include <stdio.h> #include <string.h> typedef strlIct{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); sex:b.sex; for(i=0;i<2;i++)a.score[i]=b.score[i]; return a; } main {STU c="Qian",f,95.0,92.0},d; d=f(c).printf("%s,%c,%2.0f,%2.0f",d.Name,d.sex,d.score[0],d.score[1]); } 程序的运行结果是( )。

A.Qian,f,95,92

B.Qian,m,85,90

C.Zhao,m,85,90

D.Zhao,f,95,92


正确答案:C
f函数的功能是对形参a的各个成员用结构体变量b的各个成员进行赋值后,然后返回变量a。

第5题:

有以下程序: #include<stdio.h> #include<string.h> typedef struct{char name[9];char sex;int score[2];}STU; STU f(STU a) { STU b={"Zha0","m",85,90}; int i; strcpy(a.name,b.name); sex=b.sex; for(i=o;i<2;i++)a.score[i]=b.score[i]; return a; } main( ) { STU c={"Qian",f,95,92),d; d=f(c); printf("%S,%C,%d,%d,",d.name,d.sex,d.score[0],d.score[l]); printf("%s,%c,%d,%d\n",C.name,C.sex,c.score[0],C.score[1]); } 程序运行后的输出结果是( )。

A.Zhao,m,85,90,Qian,f,95,92

B.Zhao,m,85,90,Zhao,m,85m90

C.Qian,f,95,92,Qian,f,95,92

D.Qian,f,95,92,zhan,m,85,90


正确答案:A
此题涉及C语言中的结构体,主要功能为输出b和C中的name、sex、score[0]和score[1]中的值。

第6题:

有下列程序:includeinclude "string.h"typedef struct{char name[9]; char sex;float

有下列程序: #include <stdio.h> #include "string.h" 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[i]=b.score[i]; } 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(C)后,实参传向形参,进行f()函数功能的实现,但程序中没有返回语句,故形参不能将值传回实参,它们值的传递具有不可逆性,所与printf输出的还是c中实参的值,故选项A)正确。

第7题:

有以下程序 include include typedef struct { cha

有以下程序 #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[i] = b.score[i]; return a; } main() { STU c={"Qian", T, 95.0, 92.0}, d; d=f(c); printf("%s,%c,%2.0f,%2.0f\n", d.name, &sex, &score[O], d.score[1]); } 程序的运行结果是

A.Qian, f,95,92

B.Qian,m,85,90

C.Zhao,m,85,90

D.Zhao,f,95,92


正确答案:C
解析:本题的f()函数中,首先定义了一个STU结构体变量b并初始化为{"Zhao",'m',85.0,90.0},然后分别通过strcpy()库函数、赋值语句和for循环,将b中所有成员分别赋给形参a的相应成员,最后返回a。所以,无论传递给函数fun()的参数是什么,结果返回的都会是函数中定义的STU结构体b的内容{"Zhao",'m',85.0,90.0}。故最终输出结果为:Zhao,m,85,90,应该选择C。

第8题:

有以下程序

#include <stdio.h>

main()

{

struct STU { char name[9]; char sex; double score[2];};

struct STU a={"Zhao",'m',85.0,90.0},b={"Qian",'f',95.0,92.0};

b=a;

printf("%s,%c,%2.0f,%2.0f\n", b.name, b.sex, b.score[0], b.score[1]);

}

程序的运行结果是

A)Qian,f,95,92

B)Qian,m,85,90

C) Zhao,f,95,92

D)Zhao,m,85,90


正确答案:D

第9题:

有以下程序 include main() { struct STU{char name[9];char sex;double

有以下程序 #include <stdio.h> main() { struct STU{char name[9];char sex;double score[2];}; sturt STU a={"Zhao" ,'m',85.0,90.0},b={"Qian" ,'f,95:0,92.0}; b=a; printf("%s,%c,%2.0f,%2.0f\n",b.name,b.sex,b.score[0],b.score[1]); } 程序的运行结果是______。

A.Qian,f,95,92

B.Qian,85,90

C.Zhao,f,95,92

D.Zhao,m,85,90


正确答案:D
解析:本题定义了两个结构体变量a和b,并将结构体变量a的内容赋给了结构体变量b。对于结构体的赋值,意味这将其中的每一个元素都进行赋值,所以输出的结构体变量b中的内容即为结构体变量a中的各项内容。另外本题需要注意的是输出格式的控制,其中“%2.0f”指的是输出的数据共占2列,其中有0位小数。

第10题:

有以下程序

#include<stdio.h>

#include<siring.h>

typedef struct{char name[9];char sex;int score [2];}STU;

STU f(STU a)

{ STU b={"Zhao",'m',85,90);

int i;

strcpy(a.name,b.name);

a.sex=b.sex:

for(i=0;i<2;i++) a.score [i]=b.score[i];

return a;

}

main()

STU c={"Qian",'f',95,92},d;

d=f(c):

printf("%s,%c,%d,%d,",d.name,d.sex,d.score[0],d.score[1]);

prinff("%s,%c,%d,%d\n",c.name,c.sex,c.score[0],c.score[1]);

}

程序运行后的输出结果是

A.Zhao,m,85,90,Qian,f,95,92

B.Zhao,m,85,90,Zhao,m,85,90

C.Qian,f,95,92,Qian,f,95,92

D.Qian,f,95,92,Zhao,m,85,90


正确答案:A
解析:本题考察的是结构体知识和函数调用的参数传递知识点。通过函数调用把主函数中c变量的所有数据传给了子函数中的形参a,在子函数中将b中的数据均复制到了a中,所以返回a的值给d,使得d的值为zhao,m,85,90。但是主函数中c变量的值没有任何变化,所以选择A)。

更多相关问题