1、结构体与同用体及答案解析(总分:14.00,做题时间:90 分钟)一、B选择题/B(总题数:6,分数:6.00)1.有以下结构体说明和变量定义,如图所示,指针 p、q、r 分别指向一个链表中的三个连续结点。 struct node int data; struct node*next; *p,*q,*r; (分数:1.00)A.q-next=r-next;r-next=q;p-next=r;B.q-next=r-next;p-next=r;r-next=q;C.p-next=r;q-next=r-next;r-next=q;D.r-next=q;q-next=r-next;p-next=r;2
2、.设有以下说明语句 struct num int a; float b; numl;则下面的叙述不正确的是_。(分数:1.00)A.struct是结构体类型的关键字B.struct num是用户定义的结构体类型C.numl是用户定义的结构体类型名D.a和 b都是结构体成员名3.已知: union int i; char c; float a; st;则 sizeof(st)的值是_。(分数:1.00)A.4B.5C.6D.74.已知学生记录描述为 struct student int no; char name20; char sex; struct int year; int month;
3、int day; birth; ; struct student s;变量 s中的“生日”应是“1985 年4月 4日”,下列对“生日”的正确赋值方式是_。(分数:1.00)A.year=1985;month=4;day=4;B.birtyear=1985;birtmonth=4;birtday=4;C.year=1985;month=4;day=4;D.birtyear=1985;birtmonth=4;birth,day=4;5.有以下程序 struct stu char num10;float score3; ; main() struct stu s3=“20021“,90,95,85
4、,“20022“,95,80,75,“20023“,100,95,90,*p=s; int i;float sum=0; p+; for(i=0;i3;i+)sum=sum+p-scorei; printf(“%6.2f/n“,sum); 程序运行后的输出结果是_。(分数:1.00)A.260.00B.270.00C.250.00D.285.006.有以下说明和定义语句 struct student int age;char num8; ; struct student stu3=20,“200401“,21,“200402“,10/9,“200403“; struct student*p=s
5、tu;以下选项中引用结构体变量成员的表达式错误的是_。(分数:1.00)A.(p+)-numB.p-numC.*numD.stu0.age二、B填空题/B(总题数:4,分数:8.00)7.以下程序的运行结果是_。 # include string.h typedef struct student char name10; long sno; float score; STU; main() STU a= “Liuyifei“,2001,95,b=“Shangxian“,2002,90,c= “Zhangli“,2003,95 ,d,*p= d=a; if(strcmp(a.name,b.nam
6、e)0) d=b; if(strcmp(c.name,d.name)0) d=c; printf(“%ld%s/n“,d.sno,p-name); (分数:2.00)填空项 1:_8.以下程序运行后的输出结果是_。 struct NODE int k; struct NODE *link; ; main() struct NODE m5,*p=n,*q=m+4; int i=5; while(p!=q) p-k=-i;p+; q-k=i-;q-; q-k=-i; for(i=0;i5 ;i+)printf(“%d“,mi.k); printf(“/n“); (分数:2.00)填空项 1:_9.
7、用 typedef定义整型一维数组: typedef char CHARACTER 则对整型数组 a5,b5可以定义为_。(分数:2.00)填空项 1:_10.下面程序的运行结果是_。 #includestdio.h main() union int i2; long k; char c4; t,*s= s-i0=0x12; s-i1=0x34; print f(“%1x/n“,s-k); (分数:2.00)填空项 1:_结构体与同用体答案解析(总分:14.00,做题时间:90 分钟)一、B选择题/B(总题数:6,分数:6.00)1.有以下结构体说明和变量定义,如图所示,指针 p、q、r 分别
8、指向一个链表中的三个连续结点。 struct node int data; struct node*next; *p,*q,*r; (分数:1.00)A.q-next=r-next;r-next=q;p-next=r;B.q-next=r-next;p-next=r;r-next=q;C.p-next=r;q-next=r-next;r-next=q;D.r-next=q;q-next=r-next;p-next=r; 解析:2.设有以下说明语句 struct num int a; float b; numl;则下面的叙述不正确的是_。(分数:1.00)A.struct是结构体类型的关键字B.
9、struct num是用户定义的结构体类型C.numl是用户定义的结构体类型名 D.a和 b都是结构体成员名解析:3.已知: union int i; char c; float a; st;则 sizeof(st)的值是_。(分数:1.00)A.4 B.5C.6D.7解析:4.已知学生记录描述为 struct student int no; char name20; char sex; struct int year; int month; int day; birth; ; struct student s;变量 s中的“生日”应是“1985 年4月 4日”,下列对“生日”的正确赋值方式是
10、_。(分数:1.00)A.year=1985;month=4;day=4;B.birtyear=1985;birtmonth=4;birtday=4;C.year=1985;month=4;day=4;D.birtyear=1985;birtmonth=4;birth,day=4; 解析:5.有以下程序 struct stu char num10;float score3; ; main() struct stu s3=“20021“,90,95,85,“20022“,95,80,75,“20023“,100,95,90,*p=s; int i;float sum=0; p+; for(i=0
11、;i3;i+)sum=sum+p-scorei; printf(“%6.2f/n“,sum); 程序运行后的输出结果是_。(分数:1.00)A.260.00B.270.00C.250.00 D.285.00解析:6.有以下说明和定义语句 struct student int age;char num8; ; struct student stu3=20,“200401“,21,“200402“,10/9,“200403“; struct student*p=stu;以下选项中引用结构体变量成员的表达式错误的是_。(分数:1.00)A.(p+)-numB.p-numC.*num D.stu0.a
12、ge解析:二、B填空题/B(总题数:4,分数:8.00)7.以下程序的运行结果是_。 # include string.h typedef struct student char name10; long sno; float score; STU; main() STU a= “Liuyifei“,2001,95,b=“Shangxian“,2002,90,c= “Zhangli“,2003,95 ,d,*p= d=a; if(strcmp(a.name,b.name)0) d=b; if(strcmp(c.name,d.name)0) d=c; printf(“%ld%s/n“,d.sno
13、,p-name); (分数:2.00)填空项 1:_ (正确答案:2003Zhangli)解析:8.以下程序运行后的输出结果是_。 struct NODE int k; struct NODE *link; ; main() struct NODE m5,*p=n,*q=m+4; int i=5; while(p!=q) p-k=-i;p+; q-k=i-;q-; q-k=-i; for(i=0;i5 ;i+)printf(“%d“,mi.k); printf(“/n“); (分数:2.00)填空项 1:_ (正确答案:42124)解析:9.用 typedef定义整型一维数组: typedef char CHARACTER 则对整型数组 a5,b5可以定义为_。(分数:2.00)填空项 1:_ (正确答案:CHARACTER a5,b5;)解析:10.下面程序的运行结果是_。 #includestdio.h main() union int i2; long k; char c4; t,*s= s-i0=0x12; s-i1=0x34; print f(“%1x/n“,s-k); (分数:2.00)填空项 1:_ (正确答案:340012)解析: