第十章结构体与共用体、选择题1•在说明一个结构体变量时系统分配给它的存储空间是___________ 。
(0级)A该结构体中第一个成员所需存储空间B)该结构体中最后一个成员所需存储空间C)该结构体中占用最大存储空间的成员所需存储空间D)该结构体中所有成员所需存储空间的总和2•若有以下说明和语句:struct worker{ int no; char * name; }work, * p=&work;则以下引用方式不正确的是。
(1级)A)work . no B) ( * p). no C) p->no D)work->no3.有如下定义:struct date { int year, mon th, day; };struct worklist { char n ame[20]; char sex;struct date birthday; }pers on;对结构体变量person的出生年份进行赋值时, (1级)A) year=1958C) person. birthday . year=19584.以下对结构体类型变量的定义中不正确的是A) #define STUDENT struct studentSTUDENT{ int num;float age; }std1;C) struct{ int num;float age;}std1;5.设有以下说明语句struct stu{ int a; float b; }stutype;则下面的叙述不正确的是_____________A)struct是结构体类型的关键字B)struct stu是用户定义的结构体类型C)stutype是用户定义的结构体类型名D)a和b都是结构体成员名6.C语言结构体类型变量在程序执行期间A)所有成员一直驻留在内存中B)只有一个成员主留在内存中C)部分成员驻留在内存中D)没有成员驻留在内存中下面正确的赋值语句是 _______________B)birthday . year=1958D) person. year=1958___________ 。
(1 级)B)struct stude nt { int num;float age;}std1;D) struct{ int num;float age; } stude nt;struct stude nt std1;(1级)O ( 0 级)。
(1 级)7•以下程序的运行结果是# in elude <stdio.h>mai n(){ struct date{ int year, mon th, day; }today;printf( %d\n ”,sizeof(struct date)); }A) 6 B) 8 C) 10 D)128.有如下定义struct pers on {char n ame[9]; int age;};struct person class[10]={ 17ohu ” ,“ Paul ” , 19“ Mary ” , 18,“ Adam 16,};根据上述定义,能输出字母M的语句是_____________ 。
(1级)A)prinft( "r%c,class[3].ma ne);B)pfintf( "r%c,class[3]. name[1]);C)prinft( "r%c,class[2]. name[1]);D)printf( “ %^c,class[2].name[0]);9.设有如下定义struct ss{ char n ame[10];int age;char sex;} std[3],* p=std;下面各输入语句中错误的是___________ o( 1级)A)scan f("%d",&(*p).age);B)scan f("%s",& std. name);C)scan f("%c",&std[0].sex);D)scan f("%c",&(p->sex))10.设有以下说明语句,则下面的叙述中不正确的是___________ o (1级)struct ex {int x ; float y; char z ;} example;A) struct结构体类型的关键字B) example是结构体类型名C) x,y,z都是结构体成员名D) struct ex是结构体类型11.若程序中有下面的说明和定义:struct stt{ int x;char b;}struct stt a1,a2;则会发生的情况是 _________ o ( 1级) A)程序将顺利编译、连接、执行。
B)编译出错。
C)能顺利通过编译、连接,但不能执行。
D)能顺利通过编译,但连接出错。
12•已知教师记录定义为:struct stude nt{ int no; char n ame[30]; struct{un sig ned int year;un sig ned int mon th; un sig ned int day; }birthday; } stu;struct stude nt *t = & stu;若要把变量 t 中的生日赋值为“ 为 ________ 。
( 1级)A) year = 1980;mon th = 5; day = 1; C)t.birthday.year = 1980; t.birthday. month = 5;t.birthday.day = 1;13.以下结构类型可用来构造链表的是 — A) structaa{ int a ;int * b ; }; B) structbb{ int a ;bb * b ; }; C) structcc{ int * a ; cc b ; }; D)structdd{ int * a ; aa b;};14.以下程序的输出结果是 。
(2级)amovep(int *p, int a[3][3],int n) { int i, j;for( i=0;i< n; i++)for(j=0;j< n;j++){ *p=a[i][j];p++; } } mai n(){ int *p,a[3][3]={{1,3,5},{2,4,6}}; p=(i nt *)malloc(100); amovep(p,a,3);prin tf("%d %d \n ”,p[2],p[5]);free(p); } A ) 56B ) 25C ) 34D)程序错误15. _________________________________ 以下程序的输出结果是。
( 2级)struct HAR { int x, y; struct HAR *p;} h[2]; mai n(){ h[0].x=1;h[0].y=2; h[1].x=3;h[1].y=4; h[0].p=&h[1].x; h[1].p=&h[0].x;prin tf("%d %d \n ",(h[0].p)->x,(h[1].p)->y); } A )12B )23C )14D )32二、 填空题1•有如下定义:(1级)struct {int x; int y; }s[2]={{1,2},{3,4}},* p=s;1980年5月1日”,则正确的赋值方式B) t.year = 1980;t.m on th = 5; t.day = 1;D) t-> birthday.year = 1980; t-> birthday. month= 5;t-> birthday.day = 1;_____。
( 1 级)贝U:表达式++p->x的结果是___________ 。
表达式++p->x的结果是____________ 。
2•若有定义:(2级)struct num {int a; int b; float f; }n={1,3, 5.0}};struct num * pn=&n;则表达式pn->b/n . a * ++pn->b的值是__________ ,表达式(* pn). a+pn->f的值是__________ 。
3.若要使指针p指向一个double类型的动态存储单元,请填空。
(1级)p= ___________ malloc(sizeof(double));4.设有以下结构类型说明和变量定义,则变量a在内存所占字节数是 ______________ 。
(1级)Struct stud{ char nu m[6];int s[4];double ave;} a,*p;三、程序填空题1.结构数组中存有三人的姓名和年龄,以下程序输出三人中最年长者的姓名和年龄。
请填空。
(1级)static struct man{ char name[20]; int age; }person[ ]= { li-ming ”,18, Wang-hua”,19,"zhang-ping",20}; mai n(){struct man *p ,* q; int old=0; p=pers on; for( ; (1) _____ )if(old<p->age) {q=p; (2) ____ ;}printf( %s %d", _______ (3 __________ ); }2.以下程序段的功能是统计链表中结点的个数,其中first为指向第一个结点的指针(链表不带头结点)。
请填空。
(1级)struct li nk{char data; struct link *n ext; };struct link * p, * first; int c=0; p=first;while ( (1) ) { (2) ;p= 一(3 _______ ;}3.已知head指向一个带头结点的单向链表,链表中每个结点包含数据域( data)和指针域(next),数据域为整型。
以下函数求出链表中所有链结点数据域的和值,作为函数值返回。
请填空。
(2级)struct li nk{int data; struct link *n ext; };mai n(){ struct link *head;sum(head);}sum( (1) ){ struct link *p; int s=0;p=head->n ext;while(p) {s+= (2) ; p= (3) ; }return(s);}4•已知head指向单链表的第一个结点,以下函数完成往降序单向链表中插入一个结点,插入后链表仍有序。