任务36:结构体的定义、引用和初始化 《编程语言-C语言》45分钟专题训练

| 2份
| 23页
| 149人阅读
| 1人下载

内容正文:

湖南省职教高考《编程语言—C语言》45分钟专题训练专辑,共43份试卷。试卷命题与高考紧密相关,精选具有代表性和典型性的高考常考题。旨在帮助学生系统地复习和巩固计算机类理论知识,熟悉高考题型和命题规律,提高解题能力和应试技巧,为高考取得优异成绩打下坚实的基础,本训练卷适用于即将参加计算机类高考的学生。与本专辑配套的还有湖南省职教高考《计算机应用基础》《计算机组装与维护》《计算机网络技术》45分钟专题训练专辑,欢迎同学和老师们下载使用。 《编程语言—C语言》 项目八: 结构体、共用体、链表 第36卷: 结构体的定义、引用和初始化 时间:45分钟 总分:100分 班级___________ 姓名__________ 学号__________ 成绩________ 一、选择题(共23小题,每小题2分,共46分) 1.下列选项中,对结构体类型变量定义不正确的一项是( ) A.#define STUDENT struct student STUDENT{int num;float age;}std1; B.struct student{int num;float age;}std1; C.struct{int num;float age;}std1; D.struct{int num;float age;}student; struct student std1; 【答案】D。student是一个结构体变量,不能使用变量来定义变量。 2.设有下列所述的结构体定义,则选项中对结构体变量成员不正确的引用是( ) struct pupil{char name[20];int age; int sex;}pup[5],*p=pup; A.scanf(“%s”,pup[0].name); B.scanf(“%d”,&pup[0].age); C.scanf(“%d”,&(p->sex)); D.scanf(“%d”,p->age); 【答案】D。通过scanf()给各个结构体成员输入数据时,应该使用各个成员的地址。 3.设有定义:struct stu{int n;float x;}data;int *p;,若要使得p指向data中的n域,正确的赋值语句是( ) A.p=&data.n; B.*p=data.n; C.p=(struct stu *)&data.n; D.p=(struct stu *)data.n); 【答案】A 4.若有以下结构体定义,则正确的引用或定义是( ) struct exam{int x;int y;}; A.exam.x=10; B.exam y,x; C.struct exam y=[10]; D.struct exam a;a.x=10; 【答案】D 5.下列有关结构体的叙述中,不正确的一项是( ) A.结构体是由用户自定义的一种结构类型 B.结构体中可以设定若干个不同数据类型的成员 C.结构体中成员的数据类型可以是另一个已定义的结构 D.在定义结构时,可以为成员设置默认值 【答案】D 6.设有以下说明和语句,则下列选项中表达式值为3的是( ) struct s{int i;struct s *j;}; static struct s a[3]={1,&a[1],2,&a[2],3,&a[0]},*ptr; ptr=&a[1]; A.ptr->i++ B.ptr++->i C.*ptr->i D.++ptr->i 【答案】D 7.若程序中有说明和定义:struct abc{int x;char y;}struct abc s1,s2;,则会发生的情况是( ) A.编译时出错 B.程序将顺序编译、连接、执行 C.能顺序通过编译、连接、但不能执行 D.能顺序通过编译、但连接出错 【答案】A 8.在C语言中,结构体类型变量在程序执行期间( ) A.所有成员一直驻留在内存中 B.只有一个成员驻留在内存中 C.部分成员驻留在内存中 D.没有成员驻留在内存中 【答案】A 9.在C语言中,当定义了一个结构体变量时,系统分配给它的内存是( ) A.各个成员所需内存量的总和 B.结构体中第一个成员所需内存量 C.成员中占内存量最大者所需的容量 D.结构体中最后一个成员所需内存量 【答案】A 10.在C语言中,把一些属于不同类型的数据作为一个整体来处理时,常用( ) A.简单变量 B.数组类型数据 C.指针类型数据 D.结构体类型数据 【答案】D 11.设有定义:struct stud{char num[6];int s[4];double sum;}a,*p;,则变量a在内存中所占字节数为( ) A.8 B.6 C.16 D.32 【答案】D 12.设有定义:struct data{int i;char c;double d;}x;,则下列叙述中,不正确的一项是( ) A.x的内存地址与x.i的内存地址相同 B.struct data是一个类型名 C.初始化时,可以对x的所有成员同时赋初值 D.成员i、c、d占用的是同一个存储空间 【答案】D 13.下列结构体的定义语句中,不正确的一项是( ) A.struct ord{int x;int y;int z;};struct ord a; B.struct ord{int x;int y;int z;}struct ord a; C.struct ord{int x;int y;int z;}a; D.struct{int x;int y;int z;}a; 【答案】B。C语言中结构体变量的定义有三种方法:定义结构体类型的同时定义结构体变量;使用无名结构体类型定义结构体变量;先定义结构体类型,后定义结构体变量。 14.设有定义:struct complex{int real,unreal;}data={1,8},data2;,则下列赋值语句中错误的一项是( ) A.data2=data; B.data2=(2,6); C.data2.real=data.real; D.data2.real=data.unreal; 【答案】B 15.设有定义:struct{int n;float x;}s[2],m[2]={{10,2.8},{0,0.0}};,则下列选项中的赋值语句正确的是( ) A.s[0]=m[1]; B.s=m; C.s.n=m.n; D.s[2].x=m[2].x 【答案】A 16.设有以下定义,想要将某学生的生日信息(2012年2月12日)存入结构体变量w中,正确的赋值方式是( ) struct worker { int no; char name[20]; char sex; struct birth{ int day; int month; int year;}a;}; struct worker w; A day=12;month=2;year=2012; B w.birth.day=12; w.birth.month=2; w.birth.year=2012; C w.day=12; w.month=2; w.year=2012; D w.a.day=12; w.a.month=2; w.a.year=2012; 【答案】B 17.执行以下程序段的输出结果是( ) struct s {int a;char b;double c;}; main() {printf("%d",sizeof(struct s)); getch();} A.16 B.20 C.26 D.13 【答案】A 18.下列结构体类型说明和变量定义中,正确的一项是( ) A.struct SS{char flag;float x;} struct SS a,b; B.struct {char flag;float x;}SS;SS a,b; C.struct ss{char flag;float x;};struct ss a,b; D.struct SS{char flag;float x;}SS a,b; 【答案】C 19.下列选项中,对结构体变量ab的定义中,不正确的一项是( ) A.struct{char c;int a;}ab; B.struct{char c;int a;}Y;struct Y ab; C.#define Y struct Y{char c;int a;}ab; D.typedef struct{char c;int a;}Y;Y ab; 【答案】B 20.设有定义:struct data{int x,int y;}a={11,12},b;,则下列赋值语句中,错误的一项是( ) A.a=b; B.b.x=a.x; C.b.x=a.y D.b={13,14}; 【答案】D 21.执行以下程序段的输出结果是( ) main() {struct comper{int x;int y;float z;}cm[3]={1,3,5,2,4,6,1,2,3}; printf("%d",sizeof(cm));getch();} A.12 B.24 C.32 D.36 【答案】D 22.执行以下程序段的输出结果是( ) main() {struct {int year,month,day;char a;}data; printf("%d",sizeof(data));getch();} A.5 B.8 C.12 D.16 【答案】D 23.执行以下程序的输出结果是( ) main() {struct {int year,month,day;char a;}data; data.a='A';data.month=2;data.year=2026; printf("%d",data.year%400==0||data.year%4==0&&data.year%100!=0); getch();} A.0 B.1 C.2 D.有语法错 【答案】A 二、程序运行结果题(本题共7小题,每题3分,共21分) 24.以下程序的运行结果是( ) #include <stdio.h> #include <conio.h> struct n {int x;char c;}; main() {struct n a={10,'x'}; func(a); printf("%d,%c",a.x,a.c); getch();}; int func(struct n b) {b.x=20;b.c='y';} 【答案】10,x 25.以下程序的运行结果是( ) #include <stdio.h> #include <conio.h> main( ) {static struct s1{char c[4],*s;}s1={"abc","def"}; static struct s2 {char *cp;struct s1 ssl;}s2={"ghi",{"jkl","mon"}}; printf("%c,%c-",s1.c[0],*s1.s); printf("%s,%s ",s1.c,s1.s); getch();} 【答案】a,d-abc,def 26.以下程序的运行结果是( ) #include <stdio.h> #include <conio.h> main( ) {static struct s1{char c[4],*s;}s1={"abc","def"}; static struct s2 {char *cp;struct s1 ssl;}s2={"ghi",{"jkl","mon"}}; printf("%s,%s ",s2.cp,s2.ssl.s); printf("%s,%s ",++s2.cp,++s2.ssl.s); getch();} 【答案】ghi,mon;hi,on 27.以下程序的运行结果是( ) #include <stdio.h> #include <conio.h> struct std{int num;char name[15];double m;}; void fun(struct std k) { k.num=101; strcpy(k.name,"LiLin"); k.m=1227.0;} main( ) { struct std q={101,"Wangruiyao",1995.10}; fun(q); printf("%d,%s,%6.2f ",q.num,q.name,q.m); getch();} 【答案】101,Wangruiyao,1995.10 28.以下程序的运行结果是( ) #include <stdio.h> #include <conio.h> main() {struct EX{ struct{int x;int y;}in;int a;int b;}e; e.a=1;e.b=2;e.in.x=e.a*e.b; e.in.y=e.a+e.b; printf("%d,%d",e.in.x,e.in.y); getch();} 【答案】2,3 29.以下程序的运行结果是( ) #include <stdio.h> #include <conio.h> main() {struct keyword {char key[20]; int id;} k[ ]={"void",1,"char",2,"int",3,"float",4,"double",5}; printf("%c,%d ",k[3].key[0],k[3].id); getch();} 【答案】f,4 30.以下程序的运行结果是( ) #include <stdio.h> #include <conio.h> main() {struct contry {int num;char name[20];} x[5]={1,"China",2,"USA",3,"France",4,"England",5,"Spanish"}; int i; for(i=3;i<5;i++) printf("%d%c",x[i].num,x[i].name[0]); getch();} 【答案】4E5S 三、阅读程序,修改程序中的错误,不得增行或删行,也不得更改程序结构。请指出错误代码所在的行号,并给出该行修改后的程序代码。每处3分,共9分) 31. 下列程序的功能是:定义一个复数类型,对两个复数相加。该程序中有三处错误,请改正。 L1 #include <stdio.h> L2 #include<conio.h> L3 struct complex L4 {double x,y;}; L5 void add(c1,c2) L6 {struct complex c; L7 c.x=c1.x+c2.x; L8 c.y=c1.y+c2.y; L9 return c;} L10 main() L11 {struct complex f1(3,-10),f2(10,5),f3; L12 f3=add(f1,f2); L13 printf("复数相加为x=%.2lf,y=%.2lf ",x,y); L14 getch();} 答案: L5 struct complex add(struct complex c1,struct complex c2) L11 {struct complex f1={3,-10},f2={10,5},f3; L13 printf("复数相加为x=%.2lf,y=%.2lf ",f3.x,f3.y); 四、程序填空。按照题目要求,将正确的内容填入相应位置,使得程序完整(每空3分,共24分) 32. 下列程序的功能是定义一个结构体变量(包括年、月、日),计算该日在本年中是第几天。请填空。 #include <stdio.h> #include<conio.h> 【1】 {int year; int month; int day;}date; int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; main() {int days(struct y_m_d date1); printf("input year,month,day:"); scanf("%d.%d.%d",&date.year ,&date.month,&date.day); printf("%d-%d is the %dth day in %d. ",date.month,date.day,【2】); getch();} int days(struct y_m_d date1) {int sum=0,i; for(i=0;i<【3】;i++) sum+=day[i]; sum+=【4】; if((date1.year%4==0&&date1.year%100!=0||date.year%400==0)&&【5】) sum+=1; return sum;} 答案:①struct y_m_d ②days(date),date.year ③date.month ④date1.day ⑤date1.month>=3 33.下列程序的功能是:用学生的学号、姓名、年龄、成绩定义一个结构体类型student,其中年龄为出生日期,其类型由另外一个结构体类型date来定义,最后输出该学生的全部信息。请填空。 #include <stdio.h> #include<conio.h> #include<string.h> 【1】 {int year;int month;int day;}; struct student {char name[20];int sex;【2】;int score;}; main() {struct student stu; strcpy(stu.name,"Wang ruiling"); stu.birthday.year=2008; stu.sex=2025-【3】; stu.birthday.month=5; stu.birthday.day=30; stu.score=90; printf("The information is: "); printf("%s ",stu.name); printf("%d ",stu.sex); printf("%d ",stu.birthday.year); printf("%d ",stu.birthday.month); printf("%d ",stu.birthday.day); printf("%d ",stu.score); getch();} 答案:①struct date ②struct date birthday ③(stu.birthday.year) 原创精品资源学科网独家享有版权,侵权必究! 学科网(北京)股份有限公司 $$ 湖南省职教高考《编程语言—C语言》45分钟专题训练专辑,共43份试卷。试卷命题与高考紧密相关,精选具有代表性和典型性的高考常考题。旨在帮助学生系统地复习和巩固计算机类理论知识,熟悉高考题型和命题规律,提高解题能力和应试技巧,为高考取得优异成绩打下坚实的基础,本训练卷适用于即将参加计算机类高考的学生。与本专辑配套的还有湖南省职教高考《计算机应用基础》《计算机组装与维护》《计算机网络技术》45分钟专题训练专辑,欢迎同学和老师们下载使用。 《编程语言—C语言》 项目八: 结构体、共用体、链表 第36卷: 结构体的定义、引用和初始化 时间:45分钟 总分:100分 班级___________ 姓名__________ 学号__________ 成绩________ 一、选择题(共23小题,每小题2分,共46分) 1.下列选项中,对结构体类型变量定义不正确的一项是( ) A.#define STUDENT struct student STUDENT{int num;float age;}std1; B.struct student{int num;float age;}std1; C.struct{int num;float age;}std1; D.struct{int num;float age;}student; struct student std1; 2.设有下列所述的结构体定义,则选项中对结构体变量成员不正确的引用是( ) struct pupil{char name[20];int age; int sex;}pup[5],*p=pup; A.scanf(“%s”,pup[0].name); B.scanf(“%d”,&pup[0].age); C.scanf(“%d”,&(p->sex)); D.scanf(“%d”,p->age); 3.设有定义:struct stu{int n;float x;}data;int *p;,若要使得p指向data中的n域,正确的赋值语句是( ) A.p=&data.n; B.*p=data.n; C.p=(struct stu *)&data.n; D.p=(struct stu *)data.n); 4.若有以下结构体定义,则正确的引用或定义是( ) struct exam{int x;int y;}; A.exam.x=10; B.exam y,x; C.struct exam y=[10]; D.struct exam a;a.x=10; 5.下列有关结构体的叙述中,不正确的一项是( ) A.结构体是由用户自定义的一种结构类型 B.结构体中可以设定若干个不同数据类型的成员 C.结构体中成员的数据类型可以是另一个已定义的结构 D.在定义结构时,可以为成员设置默认值 6.设有以下说明和语句,则下列选项中表达式值为3的是( ) struct s{int i;struct s *j;}; static struct s a[3]={1,&a[1],2,&a[2],3,&a[0]},*ptr; ptr=&a[1]; A.ptr->i++ B.ptr++->i C.*ptr->i D.++ptr->i 7.若程序中有说明和定义:struct abc{int x;char y;}struct abc s1,s2;,则会发生的情况是( ) A.编译时出错 B.程序将顺序编译、连接、执行 C.能顺序通过编译、连接、但不能执行 D.能顺序通过编译、但连接出错 8.在C语言中,结构体类型变量在程序执行期间( ) A.所有成员一直驻留在内存中 B.只有一个成员驻留在内存中 C.部分成员驻留在内存中 D.没有成员驻留在内存中 9.在C语言中,当定义了一个结构体变量时,系统分配给它的内存是( ) A.各个成员所需内存量的总和 B.结构体中第一个成员所需内存量 C.成员中占内存量最大者所需的容量 D.结构体中最后一个成员所需内存量 10.在C语言中,把一些属于不同类型的数据作为一个整体来处理时,常用( ) A.简单变量 B.数组类型数据 C.指针类型数据 D.结构体类型数据 11.设有定义:struct stud{char num[6];int s[4];double sum;}a,*p;,则变量a在内存中所占字节数为( ) A.8 B.6 C.16 D.32 12.设有定义:struct data{int i;char c;double d;}x;,则下列叙述中,不正确的一项是( ) A.x的内存地址与x.i的内存地址相同 B.struct data是一个类型名 C.初始化时,可以对x的所有成员同时赋初值 D.成员i、c、d占用的是同一个存储空间 13.下列结构体的定义语句中,不正确的一项是( ) A.struct ord{int x;int y;int z;};struct ord a; B.struct ord{int x;int y;int z;}struct ord a; C.struct ord{int x;int y;int z;}a; D.struct{int x;int y;int z;}a; 14.设有定义:struct complex{int real,unreal;}data={1,8},data2;,则下列赋值语句中错误的一项是( ) A.data2=data; B.data2=(2,6); C.data2.real=data.real; D.data2.real=data.unreal; 15.设有定义:struct{int n;float x;}s[2],m[2]={{10,2.8},{0,0.0}};,则下列选项中的赋值语句正确的是( ) A.s[0]=m[1]; B.s=m; C.s.n=m.n; D.s[2].x=m[2].x 16.设有以下定义,想要将某学生的生日信息(2012年2月12日)存入结构体变量w中,正确的赋值方式是( ) struct worker { int no; char name[20]; char sex; struct birth{ int day; int month; int year;}a;}; struct worker w; A day=12;month=2;year=2012; B w.birth.day=12; w.birth.month=2; w.birth.year=2012; C w.day=12; w.month=2; w.year=2012; D w.a.day=12; w.a.month=2; w.a.year=2012; 17.执行以下程序段的输出结果是( ) struct s {int a;char b;double c;}; main() {printf("%d",sizeof(struct s)); getch();} A.16 B.20 C.26 D.13 18.下列结构体类型说明和变量定义中,正确的一项是( ) A.struct SS{char flag;float x;} struct SS a,b; B.struct {char flag;float x;}SS;SS a,b; C.struct ss{char flag;float x;};struct ss a,b; D.struct SS{char flag;float x;}SS a,b; 19.下列选项中,对结构体变量ab的定义中,不正确的一项是( ) A.struct{char c;int a;}ab; B.struct{char c;int a;}Y;struct Y ab; C.#define Y struct Y{char c;int a;}ab; D.typedef struct{char c;int a;}Y;Y ab; 20.设有定义:struct data{int x,int y;}a={11,12},b;,则下列赋值语句中,错误的一项是( ) A.a=b; B.b.x=a.x; C.b.x=a.y D.b={13,14}; 21.执行以下程序段的输出结果是( ) main() {struct comper{int x;int y;float z;}cm[3]={1,3,5,2,4,6,1,2,3}; printf("%d",sizeof(cm));getch();} A.12 B.24 C.32 D.36 22.执行以下程序段的输出结果是( ) main() {struct {int year,month,day;char a;}data; printf("%d",sizeof(data));getch();} A.5 B.8 C.12 D.16 23.执行以下程序的输出结果是( ) main() {struct {int year,month,day;char a;}data; data.a='A';data.month=2;data.year=2026; printf("%d",data.year%400==0||data.year%4==0&&data.year%100!=0); getch();} A.0 B.1 C.2 D.有语法错 二、程序运行结果题(本题共7小题,每题3分,共21分) 24.以下程序的运行结果是( ) #include <stdio.h> #include <conio.h> struct n {int x;char c;}; main() {struct n a={10,'x'}; func(a); printf("%d,%c",a.x,a.c); getch();}; int func(struct n b) {b.x=20;b.c='y';} 25.以下程序的运行结果是( ) #include <stdio.h> #include <conio.h> main( ) {static struct s1{char c[4],*s;}s1={"abc","def"}; static struct s2 {char *cp;struct s1 ssl;}s2={"ghi",{"jkl","mon"}}; printf("%c,%c-",s1.c[0],*s1.s); printf("%s,%s ",s1.c,s1.s); getch();} 26.以下程序的运行结果是( ) #include <stdio.h> #include <conio.h> main( ) {static struct s1{char c[4],*s;}s1={"abc","def"}; static struct s2 {char *cp;struct s1 ssl;}s2={"ghi",{"jkl","mon"}}; printf("%s,%s ",s2.cp,s2.ssl.s); printf("%s,%s ",++s2.cp,++s2.ssl.s); getch();} 27.以下程序的运行结果是( ) #include <stdio.h> #include <conio.h> struct std{int num;char name[15];double m;}; void fun(struct std k) { k.num=101; strcpy(k.name,"LiLin"); k.m=1227.0;} main( ) { struct std q={101,"Wangruiyao",1995.10}; fun(q); printf("%d,%s,%6.2f ",q.num,q.name,q.m); getch();} 28.以下程序的运行结果是( ) #include <stdio.h> #include <conio.h> main() {struct EX{ struct{int x;int y;}in;int a;int b;}e; e.a=1;e.b=2;e.in.x=e.a*e.b; e.in.y=e.a+e.b; printf("%d,%d",e.in.x,e.in.y); getch();} 29.以下程序的运行结果是( ) #include <stdio.h> #include <conio.h> main() {struct keyword {char key[20]; int id;} k[ ]={"void",1,"char",2,"int",3,"float",4,"double",5}; printf("%c,%d ",k[3].key[0],k[3].id); getch();} 30.以下程序的运行结果是( ) #include <stdio.h> #include <conio.h> main() {struct contry {int num;char name[20];} x[5]={1,"China",2,"USA",3,"France",4,"England",5,"Spanish"}; int i; for(i=3;i<5;i++) printf("%d%c",x[i].num,x[i].name[0]); getch();} 三、阅读程序,修改程序中的错误,不得增行或删行,也不得更改程序结构。请指出错误代码所在的行号,并给出该行修改后的程序代码。每处3分,共9分) 31. 下列程序的功能是:定义一个复数类型,对两个复数相加。该程序中有三处错误,请改正。 L1 #include <stdio.h> L2 #include<conio.h> L3 struct complex L4 {double x,y;}; L5 void add(c1,c2) L6 {struct complex c; L7 c.x=c1.x+c2.x; L8 c.y=c1.y+c2.y; L9 return c;} L10 main() L11 {struct complex f1(3,-10),f2(10,5),f3; L12 f3=add(f1,f2); L13 printf("复数相加为x=%.2lf,y=%.2lf ",x,y); L14 getch();} 四、程序填空。按照题目要求,将正确的内容填入相应位置,使得程序完整(每空3分,共24分) 32. 下列程序的功能是定义一个结构体变量(包括年、月、日),计算该日在本年中是第几天。请填空。 #include <stdio.h> #include<conio.h> 【1】 {int year; int month; int day;}date; int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; main() {int days(struct y_m_d date1); printf("input year,month,day:"); scanf("%d.%d.%d",&date.year ,&date.month,&date.day); printf("%d-%d is the %dth day in %d. ",date.month,date.day,【2】); getch();} int days(struct y_m_d date1) {int sum=0,i; for(i=0;i<【3】;i++) sum+=day[i]; sum+=【4】; if((date1.year%4==0&&date1.year%100!=0||date.year%400==0)&&【5】) sum+=1; return sum;} 33.下列程序的功能是:用学生的学号、姓名、年龄、成绩定义一个结构体类型student,其中年龄为出生日期,其类型由另外一个结构体类型date来定义,最后输出该学生的全部信息。请填空。 #include <stdio.h> #include<conio.h> #include<string.h> 【1】 {int year;int month;int day;}; struct student {char name[20];int sex;【2】;int score;}; main() {struct student stu; strcpy(stu.name,"Wang ruiling"); stu.birthday.year=2008; stu.sex=2025-【3】; stu.birthday.month=5; stu.birthday.day=30; stu.score=90; printf("The information is: "); printf("%s ",stu.name); printf("%d ",stu.sex); printf("%d ",stu.birthday.year); printf("%d ",stu.birthday.month); printf("%d ",stu.birthday.day); printf("%d ",stu.score); getch();} 原创精品资源学科网独家享有版权,侵权必究! 学科网(北京)股份有限公司 $$

资源预览图

任务36:结构体的定义、引用和初始化  《编程语言-C语言》45分钟专题训练-第1页
1
任务36:结构体的定义、引用和初始化  《编程语言-C语言》45分钟专题训练-第2页
2
任务36:结构体的定义、引用和初始化  《编程语言-C语言》45分钟专题训练-第3页
3

由于学科网是一个信息分享及获取的平台,不确保部分用户上传资料的 来源及知识产权归属。如您发现相关资料侵犯您的合法权益,请联系学科网,我们核实后将及时进行处理。