2022年湖北专升本C语言结构体与共用体模拟题
一、单项选择题
1.以下程序的输出结果是( D )。
struct student
{char name[20];
char sex;
int age;
}stu[3]={“Li Lin”,‘M’, 18, “Zhang Fun”,‘M’, 19, “Wang Min”,‘F’, 20};
main()
{struct student *p;
p=stu;
printf(“%s, %c, %d\n”, p->name, p->sex, p->age);
}
A) Wang Min,F,20
B) Zhang Fun,M,19
C) Li Lin,F,19
D) Li Lin,M,18
2.设有以下语句:
struct st{int n; struct st *next;};
static struct st a[3]={5, &a[1], 7, &a[2], 9,‘\0’},*p;
p=&a[0];
则表达式(D)的值是 6。
A) p++ ->n
B) p->n++
C) (*p).n++
D) ++p->n
3.以下四个程序中,( C )不能对两个整型变量的值进行交换。
A) #include
main()
{int a=10,b=20;
swap(&a,&b);
printf(“%d %d\n”,a,b);
}
swap(int *p,int *q)
{int *t;
t=(int *)malloc(sizeof(int));
*t=*p; *p=*q; *q=*t;
}
B) main()
{int a=10,b=20;
swap(&a,&b);
printf(“%d %d\n”,a,b);
}
swap(int *p,int *q)
{int t;
t=*p; *p=*q; *q=t;
}
C) main()
{int *a,*b;
*a=10; *b=20;
swap(a,b);
printf(“%d %d\n”,*a,*b);
}
swap(int *p,int *q)
{int t;
t=*p; *p=*q; *q=t;
}
D) main()
{int a=10,b=20;
int *x=&a,*y=&b;
swap(x,y);
printf(“%d %d\n”,a,b);
}
swap(int *p,int *q)
{int t;
t=*p; *p=*q; *q=t;
}
4.下面程序的输出结果是( C)。
struct st
{int x;
int *y;
}*p;
int dt[4]={10, 20, 30, 40};
struct st aa[4]={50, &dt[0], 60, &dt[1], 70, &dt[2], 80, &dt[3]};
main()
{p=aa;
printf(“%d”, ++p->x);
printf(“%d”, (++p)->x);
printf(“%d\n”, ++(*p->y));
}
A) 10 20 20
B) 50 60 21
C) 51 60 21
D) 60 70 31
5.若要用下面的程序片段使指针变量 p 指向一个存储整型数据的动态存储单元,则应填入( D )。
int *p;
p= malloc(sizeof(int));
A) int
B) int *
C) (* int)
D) (int *)
6.若已建立下面的链表结构,指针 p、s 分别指向图中所示的结点,则不能将 s 所指的结点插入到链表末尾的语句组是( C)。
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;
7.以下程序的输出结果是( D)。
#include
void fun(float *p1,float *p2, float *s)
{s=(float *)calloc(1, sizeof(float));
*s=*p1+*(p2++);
}
main()
{float a[2]={1.1, 2.2}, b[2]={10.0, 20.0}, *s=a;
fun (a, b, s);
printf(“%f\n”, *s);
}
A) 11.100000 B) 12.100000 C) 21.100000 D) 1.100000
8.字符‘0’的 ASCII 码的十进制数为 48,且数组的第 0 个元素在低位,则以下程序的输出结果是( B )。
A) 39
B) 9
C) 38
D) 8
9.若有说明:long *p, a; 则不能通过 scanf 语句正确给输入项读入数据的程序段是( A )。
A) *p=&a; scanf(“%ld”,p);
B) p=(long *)malloc(8); scanf(“%ld”,p);
C) scanf(“%ld”,p=&a);
D) scanf(“%ld”,&a);
10.以下选项中,能定义 s 为合法的结构体变量的是(B)。
A) typedef struct abc
{double a;
char b[10];
}s;
B) struct
{double a;
char b[10];
}s;
C) struct ABC
{double a;
char b[10];
}
ABC s;
D) typedef ABC
{ double a;
char b[10];
}
ABC s;
11.设有以下定义和语句,则输出结果是(指针变量占 2 个字节)( D)。
struct date
{long *cat;(2 字节)
struct date *next;(2 字节)
double dog;(8 字节)
}too;
printf(“%d”, sizeof(too));
A) 20
B) 16
C) 14
D) 12
12.以下程序的输出结果是(D)。
#include
int a[3][3]={1, 2, 3, 4, 5, 6, 7, 8, 9}, *p;
main()
{p=(int *)malloc(sizeof(int));
f(p, a);
printf(“%d\n”,*p);
}
f(int *s, int p[][3])
{*s=p[1][1];}
A) 1
B) 4
C) 7
D) 5
13.设有如下定义:
struct
sk
{int a; float b;} data, *p;
若有 p=&data,则对 data 中的成员 a 的正确引用是( B )。
A) (*p).data.a
B) (*p).a C) p->data.a
D) p.data.a
14.以下程序的输出结果是( B )。
#include
struct stu
{int num;
char name[10];
int age;
};
void fun(struct stu *p)
{printf(“%s\n”, (*p).name);}
main()
{struct stu students[3]={{9801, “Zhang”, 20}, {9802, “Wang”, 19}, {9803, “Zhao”, 18}};
fun (students+2);
}
A) Zhang
B) Zhao
C) Wang
D) 18
15.以下程序运行后,输出结果是( C)。
fut(int **s, int p[2][3])
{**s=p[1][1];}
main()
{int a[2][3]={1, 3, 5, 7, 9, 11}, *p;
p=(int *)malloc(sizeof(int));
fut(&p, a);
printf(“%d\n”, *p);
}
A) 1
B) 7
C) 9
D) 11
16.下列程序的输出结果是( B)。
struct abc
{ int a, b, c; };
main()
{ struct abc s[2]={{1,2,3},{4,5,6}}; int t;
t=s[0].a + s[1].b;
printf("%d \n", t);
}
A) 5
B) 6
C) 7
D) 8
17.有以下结构体说明和变量的定义,且如下图所示指针 p 指向变量 a,指针 q 指向变量 b。则不能把结点 b 连接到结点 a 之后的语句是( B)。
struct node
{char data;
struct node *next;
} a, b, *p=&a,*q=&b;
A) a.next=q;
B) p.next=&b;
C) p->next=&b;
D) (*p).next=q;
18.变量 a 所占内存字节数是(C)。
A) 4
B) 5
C) 6
D) 8
19.有如下定义:
struct person{char name[9]; int age;};
struct person class[10]={“Johu”, 17, “Paul”, 19 , “
Mary”, 18, “Adam”, 16};
根据上述定义,能输出字母 M 的语句是( D)。
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]);
20.以下对结构体类型变量的定义中,不正确的是( C)。
A) typedef struct aa
{int n;
float m;
}AA;
AA td1;
B) #define AA struct aa
AA{int n;
float m;
}td1;
C) struct
{ int n;
float m;
}aa;
struct aa td1;
D) struct
{ int n;
float m;
}td1;
21.设有以下说明语句:
struct ex
{int x; float y; char z;} example;
则下面的叙述中不正确的是( B )。
A) struct 是结构体类型的关键字
B) example 是结构体类型名
C) x, y, z 都是结构体成员名
D) struct ex 是结构体类型名
22.以下程序的输出结果是( D)。
union myun
{ struct
{ int x, y, z; } u;
int k;
} a;
main()
{a.u.x=4; a.u.y=5; a.u.z=6;
a.k=0;
printf(%d\n", a.u.x);
}
A) 4
B) 5
C) 6
D) 0
二、填空题
1.设有以下结构体类型说明和变量定义,则变量 a 在内存中所占的字节数是22,变量 p 在内存中所占的字节数是2。
struct stud
{char num[6];
int s[4];
double ave;
}a, *p;
2.若有如下结构体说明:
struct STRU
{int a, b ; char c; double d:
struct STRU p1, p2;
};
请填空,以完成对 t 数组的定义,t 数组的每个元素为该结构体类型:struct STRU t[20];
3.以下程序段用于构成一个简单的单向链表,请填空。
struct STRU
{int x, y ;
float rate;
struct STRU * p;
} a, b;
a.x=0; a.y=0; a.rate=0; a.p=&b;
b.x=0; b.y=0; b.rate=0; b.p=NULL;
4.建立并输出 100 个同学的通讯录,每个通讯录包括同学的姓名、地址、邮政编码。
#include
#define N 100
struct communication
{char name[20];
char address[80];
long int post_code;
}commun[N];
main()
{int i;
for(i=0; i<100; i++)
{set_record(commun+i);
print_record(commun+i);
}}
set_record(struct communication *p)
{printf(“Set a communication record\n”);
scanf(“%s %s %ld”, p->name, p->address, p->post-code);
}
print_record ( strut communication*p)
{printf(“Print a communication record\n”);
printf(“Name: %s\n”, p->name);
printf(“Address: %s\n”, p->address);
printf(“Post_code: %ld\n”, p->post-code);
}
5.以下函数 creatlist 用来建立一个带头节点的单链表,新的结点总是插入在链表的末尾。链表的头指针作为函数值返回,链表最后一个节点的 next 成员中放入 NULL,作为链表结束标志。读入时字符以#表示输入结束(#不存入链表)。请填空。
struct node
{char data;
struct node * next;
};
struct node * creatlist( )
{struct node * h,* s,* r;char ch;
h=(struct node *)malloc(sizeof(struct node));
r=h;
ch=getchar( );
while(ch!=‘#’)
{s=(struct node *)malloc(sizeof(struct node));
s->data=ch;
r->next=s; r=s;
ch=getchar( );}
r->next=NULL;
return h;
}
6.有以下定义和语句,则 sizeof(a)的值是10,而 sizeof(a.share)的值是 4。
struct date
{int day;
int month;
int year;
union
{int share1;
float share2;
}share;
} a;
以上就是关于2022年湖北专升本C语言结构体与共用体模拟题的全部内容了,如果你还有专升本相关的疑惑(如专升本报名、考试动态、院校招生简章、统考动态、湖南专升本院校、历年真题、考试大纲、专升本等相关信息),可以在文章下方留下你的联系方式,老师会第一时间联系到你,为你答疑解惑哦!
部分内容来源于网络转载、学生投稿,如有侵权或对本站有任何意见、建议或者投诉,请联系邮箱(1296178999@qq.com)反馈。 未经本站授权,不得转载、摘编、复制或者建立镜像, 如有违反,本站将追究法律责任!
本文标签: 统招专升本全日制专升本统招 上一篇:2022年湖北专升本C语言指针模拟题 下一篇:2022年湖北专升本C语言文件模拟题