结构体与联合体习题含答案.docx

上传人:b****7 文档编号:25183051 上传时间:2023-06-05 格式:DOCX 页数:11 大小:52.70KB
下载 相关 举报
结构体与联合体习题含答案.docx_第1页
第1页 / 共11页
结构体与联合体习题含答案.docx_第2页
第2页 / 共11页
结构体与联合体习题含答案.docx_第3页
第3页 / 共11页
结构体与联合体习题含答案.docx_第4页
第4页 / 共11页
结构体与联合体习题含答案.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

结构体与联合体习题含答案.docx

《结构体与联合体习题含答案.docx》由会员分享,可在线阅读,更多相关《结构体与联合体习题含答案.docx(11页珍藏版)》请在冰豆网上搜索。

结构体与联合体习题含答案.docx

结构体与联合体习题含答案

2013年结构体与联合体习题

选择题

1、若程序中有以下的说明和定义:

structabc

{intx;chary;}花括号后少了分号。

structabcs1,s2;

则会发生的情况是______。

A)编译时错B)程序将顺序编译、连接、执行

C)能顺序通过编译、连接、但不能执行D)能顺序通过编译、但连接出错

2、有以下程序段

structst

{intx;int*y;}*pt;

inta[]={1,2};b[]={3,4};

structstc[2]={10,a,20,b};

pt=c;

以下选项中表达式的值为11的是

A)*pt->yB)pt->xC)++pt->xD)(pt++)->x

3、有以下说明和定义语句

structstudent

{intage;charnum[8];};

structstudentstu[3]={{20,"200401"},{21,"200402"},{19,"200403"}};

structstudent*p=stu;

以下选项中引用结构体变量成员的表达式错误的是______。

A)(p++)->numB)p->numC)(*p).numD)stu[3].age

4、设有如下枚举类型定义

enumlanguage{Basic=3,Assembly=6,Ada=100,COBOL,Fortran};

枚举量Fortran的值为______。

A)4B)7C)102D)103

5、以下叙述中错误的是_________。

A)可以通过typedef增加新的类型

B)可以用typedef将已存在的类型用一个新的名字来代表

C)用typedef定义新的类型名后,原有类型名仍有效

D)用typedef可以为各种类型起别名,但不能为变量起别名

6、有以下程序段

typedefstructNODE

{intnum;structNODE*next;

}OLD;

以下叙述中正确的是

A)以上的说明形式非法B)NODE是一个结构体类型

C)OLD是一个结构体类型D)OLD是一个结构体变量

7、以下选项中不能正确把cl定义成结构体变量的是______。

1.typedefstruct

{intred;

intgreen;

intblue;

}COLOR;

COLORcl;

2.structcolorcl

{intred;

intgreen;

intblue;

};

3.structcolor

{intred;

intgreen;

intblue;

}cl;

4.struct

{intred;

intgreen;

intblue;

}c1;

A)1B)2C)3D)4

8、设有以下语句

typedefstructS

{intg;charh;}T;

则下面叙述中正确的是______。

A)可用S定义结构体变量

B)可以用T定义结构体变量

C)S是struct类型的变量

D)T是structS类型的变量

9、设有如下说明

typedefstructST

{longa;intb;charc[2];}NEW;

则下面叙述中正确的是_____。

A)以上的说明形式非法

B)ST是一个结构体类型

C)NEW是一个结构体类型

D)NEW是一个结构体变量

10、以下对结构体类型变量td的定义中,错误的是______。

A)typedefstructaaB)structaa

{intn;{intn;

floatm;floatm;

}AA;};

AAtd;structaatd;

C)structD)struct

{intn;{intn;

floatm;floatm;

}aa;}td;

structaatd;

11、根据下面的定义,能打印出字母M的语句是_____。

structperson{charname[9];intage;};

structpersonclass[10]={"John",17,"Paul",19,"Mary",18,"Adam",16};

A)printf("%c\n",class[3].name);B)printf("%c\n",class[3].name[1]);

C)printf("%c\n",class[2].name[1]);D)printf("%c\n",class[2].name[0]);

12、设有以下语句:

structst{intn;structst*next;};

staticstructsta[3]={5,&a[1],7,&a[2],9,'\0'},*p;

p=&a[0];

则表达式   的值是6。

A)p++->nB)p->n++C)(*p).n++D)++p->n

13、下面程序的输出结果为

structst

{intx;

int*y;

}*p;

intdt[4]={10,20,30,40};

structstaa[4]={50,&dt[0],60,&dt[1],70,&dt[2],80,&dt[3]};

main()

{p=aa;

printf("%d\n",++p->x);

printf("%d\n",(++p)->x);

printf("%d\n",++(*p->y));

}

A)10B)50C)51D)60

20606070

20212131

14、若已建立下面的链表结构,指针p、s分别指向图中所示的结点,则不能将s所指的结点插入到链表末尾的语句组是__________。

A)s->next=NULL;p=p->next;p->next=s;

B)p=p->next;s->next=p->next;p->next=s;

C)p=p->next;s->next=p;p->next=s;

D)p=(*p).next;(*s).next=(*p).next;(*p).next=s;

15、下面程序的输出是

main()

{enumteam{my,your=4,his,her=his+10};

printf("%d%d%d%d\n",my,your,his,her);}

A)0123B)04010C)04515D)14515

16、下面程序的输出是

main()

{structcmplx{intx;inty;}cnum[2]={1,3,2,7};

printf("%d\n",cnum[0].y/cnum[0].x*cnum[1].x);}

A)0B)1C)3D)6

17、设有如下定义:

structsk

{inta;floatb;}data,*p;

若有p=&data;,则对data中的a域的正确引用是__________。

A)(*p).B)(*p).aC)p->D)、有以下程序:

*

#include<>

unionpw

{inti;charch[2];}a;

main()

{[0]=13;[1]=0;printf("%d\n",;}

程序的输出结果是 。

(注意:

ch[0]在低字节,ch[1]在高字节。

A)13B)14C)208D)209

19、已知字符0的ASCII码为十六进制的30,下面程序的输出是___________。

main()

{union{unsignedcharc;

unsignedinti[4];

}z;

[0]=0x39;

[1]=0x36;

printf("%c\n",;}

A)6B)9C)0D)3

20、字符'0'的ASCII码的十进制数为48,且数组的第0个元素在低位,则以下程序的输出结果是_____________。

#include<>

main()

{union{inti[2];longk;charc[4];}r,*s=&r;

s->i[0]=0x39;

s->i[1]=0x38;

printf("%c\n",s->c[0]);}

A)39B)9C)38D)8

填空题

1、以下函数creat用来建立一个带头结点的单向链表,新产生的结点总是插在链表的末尾。

单向链表的头指针作为函数值返回.请填空:

#include<>

structlist{chardata;structlist*next;};

structlist*creat()

{structlist*h,*p,*q;

charch;

h= (structlist*)malloc(sizeof(structlist));

p=q=h;

ch=getchar();

while(ch!

='')

{p= (structlist*)malloc(sizeof(structlist));

p->data=ch;

p->next=p;

q=p;

ch=getchar();

}

p->next='\0';

return(h);

}

2、有以下说明定义和语句,可用引用结构体成员day,请写出引用结构体成员的其它两种形式 (*b).day  、  b->day 。

struct{intday;charmouth;intyear;}a,*b;b=&a;

3、现有如图所示的存储结构,每个结点含两个域,data是指向字符串的指针域,next是指向结点的指针域。

请填空完成此结构的类型定义和说明。

structlink

{ char*data  ; structlink*next  ;}*head;

4、若有以下说明和定义语句,则变量w在内存中所占的字节数是40。

unionaa

{floatx,y;

charc[6];

};

structst{unionaav;floatw[5];doubleave;}w;

spnextdata

┌─┬─┬─┐

root││││

└─┴─┴─┘

请填空,完成此结构的类型说明和变量root的定义

structlist

{char*sp;

_structlist*next______;

_intdata______;

}root;

11、设有以下定义

structss

{intinfo;structss*link;}x,y,z;

且已建立如下图所示链表结构:

_______________

|||||||||

||-|→||-|→|||

|__|__||__|__||__|__|

xyz

请写出删除结点y的赋值语句_=z;_____。

12、以下程序的运行结果是2002Shangxian

#include<>

typedefstructstudent{

charname[10];

longsno;

floatscore;

}STU;

main()

{STU

a={“zhangsan”,2001,95},b={“Shangxian”,2002,90},c={“Anhua”,2003,95},d,*p=&d;

d=a;

if(strcmp,>0)d=b;

if(strcmp,>0)d=c;

printf(“%ld%s\n”,,p->name);}

13、以下程序运行后的输出结果是13431

structNODE

{intk;

structNODE*link;

};

main()

{

structNODEm[5],*p=m,*q=m+4;

inti=0;

while(p!

=q)

{p->k=++i;p++;

q->k=i++;q--;

}

q->k=i;

for(i=0;i<5;i++)

printf("%d",m[i].k);

printf("\n");

}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 卡通动漫

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1