有以下程序:#include <stdio.h>#include <string.h>typedef struct{ c

题目
单选题
有以下程序:#include #include typedef struct{ char name[9]; char sex; float score[2];} STU;void f(STU *A){ strcpy(a->name,Zhao); a->sex='m'; a->score[1]=90.0;}main(){ STU c = {Qian,'f',95.0,92.0},*d=&c; f(d); printf(%s,%c,%2.0f,%2.0f, d->name, c.sex, c.score[0], c.score[1]);}程序的运行结果是(  )。
A

Qian,f,95,92

B

Zhao,f,95,90

C

Zhao,m,95,90

D

Zhao,f,95,92

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

第1题:

有下列程序: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)正确。

第2题:

有以下程序 include typedef struct { int num;double s; }REC; void funl(REC *x) { x

有以下程序 include<stdio.h> typedef struct { int num;double s; }REC; void funl(REC *x) { x->num=23;x->s=88.5; } void main() { REC a={16,90.0}; fun1(&A); printf("%d\n",a.num); } 程序运行后的输出结果是( )。


正确答案:23
23

第3题:

以下四个程序中,完全正确的是( )。A.includeB.include main(); main() {/*pr

以下四个程序中,完全正确的是( )。

A.#include<stdio.h>

B.#include<stdio.h> main(); main() {/*programming*/ {/*/programming/*/ printf("programming!\n");} printf("programming!\n");}

C.#include<stdio.h>

D.include<stdio.h> main() main() {/*/*programming*/*/ {/*programming*/ printf("programming!\n");} printf("programming!\n");}


正确答案:B
解析:选项A中的main()后面不能直接用分号。选项C中的注释符使用不正确,编译器会把从第一个“/*到第一个*/”之间的当作注释,最后一个“*/”会被作为程序代码去编译。选项D中的include前要加上#表示是预定义语句。

第4题:

有以下程序 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。

第5题:

以下程序的输出结果是()includeincludemain(){char str[12]={'s','t','r',

以下程序的输出结果是( ) #include<stdio.h> #include<string.h> main() {char str[12]={'s','t','r','i','n','g'}; printf("%d\n",strlen(str)); }

A.6

B.7

C.11

D.12


正确答案:A

第6题:

以下程序的运行结果是

#include "stdio.h"

main()

{struct date

{int year,month,day;}today;

printf("%d\n",sizeof(struct date));

}

A.6

B.8

C.10

D.12


正确答案:A

第7题:

有以下程序:includeincludemain(){char a[]={'a','b','c','d','e','f','g'

有以下程序: #include <stdio.h> #include <string.h> main() { char a[]={'a','b','c','d','e','f','g','h','\0'}; int i,j; i=sizeof(a); j=strlen(a); printf("%d,%d\n",i,j); } 程序运行后的输出结果是( )。

A.9,9

B.8,9

C.1,8

D.9,8


正确答案:D
解析:sizeof是求字节运算符,在字符数组a中,“\0”也作为字节保存,是a数组的一个成员,所以sizeof(a)的值应为9;strlen是测试字符串长度的函数,函数的值为字符串中的实际长度,不包括“\0”在内,所以strlen(a)的值为8。

第8题:

有以下程序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的值。

第9题:

有以下程序 include struct tt { int x; struct tt *y; } *p; s

有以下程序 #include <stdio.h> struct tt { int x; struct tt *y; } *p; struct tt a[4]= {20,a+ 1,15,a+2,30,a+3,17,a}; main() { int i; p=a; for(i=1; i<-2; i++) { printf("%d,", p->x ); p=p->y; }

A.20,30,

B.30,17

C.15,30,

D.20,15,


正确答案:D
解析:题目中定义了一个全局结构体数组a,结构体中包含两个成员:一个int型变量x和一个自身类型指针y。所以,结构体数组a的初始化列表中每两个初始化一个结构体元素。主函数通过一个for循环,连续调用了两次输出函数printf(),每次输出p所指元素的x成员值。p初始化时指向数组 a的首地址,即a[0]的位置,所以第1次输出的值为20。然后又将a[0]的成员y的值赋给p,y在初始化时是a+1,所以p在第2次输出时指向的元素是a[1],故第2次输出的值为15。所以本题最终输出结果是“20,15,”,应该选择D。

第10题:

下列程序的运行结果为【】。 include include {int a; char b[10]; double c;};

下列程序的运行结果为【 】。

include<stdio.h>

include<string.h>

{ int a; char b[10]; double c; };

void f (struct A *t);

main()

{ struct A a={1001,"ZhangDa",1098.0};

f(&a) ; printf("%d,%s,%6.lf\n",a.a,a.b,a.C);

}

void f(struct A*t)

{ strcpy(t->b, "ChangRong");}


正确答案:1001ChangRong1098.0
1001,ChangRong,1098.0 解析:本题主要考查结构体变量赋初值,刚一开始给a赋值1001,b数组什"zhangDa",c赋值1098.0,由于被调函数中引用了结构体成员b,因此在使用strcpy时,strcpy(字符数组1,字符串2),作用是将字符串2复制到字符数组1中, b数组变成了"ChangRong",所以在最后输出时,结果为:1001,ChangRong,1098.0。

更多相关问题