版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
北邮c语言考试题及答案一、选择题(8题,每题3分,共24分)
1.下列哪个不是C语言的关键字?
A.int
B.float
C.string
D.double
2.在C语言中,如何声明一个指向整数的指针?
A.int*ptr;
B.ptr=int;
C.intptr;
D.*intptr;
3.以下哪个语句是正确的?
A.if(x=y)...
B.if(x==y)...
C.ifx==y...
D.if(x!=y)...
4.以下哪个循环会无限执行?
A.for(inti=0;i<10;i--)...
B.while(i<10)...
C.do{...}while(i<10);i++;
D.for(inti=0;i<10;i++)...
5.以下哪个函数用于动态分配内存?
A.malloc
B.free
C.realloc
D.alloftheabove
6.在C语言中,如何定义一个结构体?
A.struct{
inta;
floatb;
}myStruct;
B.structmyStruct{
inta;
floatb;
};
C.typedefstruct{
inta;
floatb;
}myStruct;
D.alloftheabove
7.以下哪个是正确的字符串声明?
A.charstr[10];
B.char*str;
C.str="Hello";
D.alloftheabove
8.以下哪个运算符的优先级最高?
A.+
B.*
C.&&
D.==
二、(一)多项选择题(5题,每题4分,共20分)
1.以下哪些是C语言的基本数据类型?
A.int
B.char
C.float
D.string
E.double
2.以下哪些是C语言的循环结构?
A.for
B.while
C.do-while
D.if
E.switch
3.以下哪些是C语言的输入输出函数?
A.printf
B.scanf
C.getchar
D.putchar
E.read
4.以下哪些是C语言中的运算符?
A.+
B.-
C.*
D./
E.==
5.以下哪些是C语言中的指针操作?
A.*
B.&
C.->
D.->
E.++
(二)判断题(5题,每题2分,共10分)
1.C语言中的变量必须先声明后使用。()
2.C语言中的数组大小必须是常数。()
3.C语言中的函数可以嵌套定义。()
4.C语言中的字符串可以用单引号声明。()
5.C语言中的指针可以指向任何类型的数据。()
三、(一)填空题(5题,每题4分,共20分)
1.在C语言中,用于表示逻辑非的运算符是_______。
2.在C语言中,用于动态释放内存的函数是_______。
3.在C语言中,用于声明常量的关键字是_______。
4.在C语言中,用于判断两个值是否相等的运算符是_______。
5.在C语言中,用于声明结构体的关键字是_______。
(二)计算题(5题,每题6分,共30分)
1.写一个C语言程序,声明一个整型数组,大小为10,并初始化所有元素为1。
2.写一个C语言程序,声明一个指向整数的指针,并使用该指针访问数组中的第一个元素。
3.写一个C语言程序,声明一个结构体,包含姓名和年龄两个成员,并创建一个该结构体的变量。
4.写一个C语言程序,使用循环计算1到10的所有整数之和。
5.写一个C语言程序,使用函数计算两个整数的最大公约数。
四、综合题(2题,每题15分,共30分)
1.写一个C语言程序,实现一个简单的学生成绩管理系统,包括添加学生信息、显示学生信息、修改学生信息、删除学生信息等功能。
2.写一个C语言程序,实现一个简单的文本编辑器,包括插入文本、删除文本、查找文本等功能。
五、材料分析题(1题,20分)
分析以下C语言代码,说明其功能并解释其工作原理。
#include<stdio.h>
structNode{
intdata;
structNode*next;
};
voidappend(structNode**head_ref,intnew_data){
structNode*new_node=(structNode*)malloc(sizeof(structNode));
structNode*last=*head_ref;
new_node->data=new_data;
new_node->next=NULL;
if(*head_ref==NULL){
*head_ref=new_node;
return;
}
while(last->next!=NULL){
last=last->next;
}
last->next=new_node;
}
voidprintList(structNode*node){
while(node!=NULL){
printf("%d",node->data);
node=node->next;
}
}
intmain(){
structNode*head=NULL;
append(&head,1);
append(&head,2);
append(&head,3);
printList(head);
return0;
}
答案部分:
一、选择题
1.C
2.A
3.B
4.B
5.D
6.D
7.A
8.B
二、(一)多项选择题
1.A,B,C,E
2.A,B,C
3.A,B,C,D
4.A,B,C,D,E
5.A,B,C,E
(二)判断题
1.√
2.√
3.×
4.×
5.√
三、(一)填空题
1.!
2.free
3.const
4.==
5.struct
(二)计算题
1.
#include<stdio.h>
intmain(){
intarr[10]={1,1,1,1,1,1,1,1,1,1};
return0;
}
2.
#include<stdio.h>
intmain(){
intarr[10]={1,2,3,4,5,6,7,8,9,10};
int*ptr=arr;
printf("%d\n",*(ptr+0));
return0;
}
3.
#include<stdio.h>
structStudent{
charname[50];
intage;
};
intmain(){
structStudents1={"John",20};
return0;
}
4.
#include<stdio.h>
intmain(){
intsum=0;
for(inti=1;i<=10;i++){
sum+=i;
}
printf("%d\n",sum);
return0;
}
5.
#include<stdio.h>
intgcd(inta,intb){
if(b==0){
returna;
}
returngcd(b,a%b);
}
intmain(){
inta=24,b=36;
printf("%d\n",gcd(a,b));
return0;
}
四、综合题
1.
#include<stdio.h>
#include<stdlib.h>
structStudent{
charname[50];
intage;
};
voidaddStudent(structStudent**students,int*count,char*name,intage){
(*students)=(structStudent*)realloc(*students,(*count+1)*sizeof(structStudent));
(*students)[*count].age=age;
strcpy((*students)[*count].name,name);
(*count)++;
}
voidprintStudents(structStudent*students,intcount){
for(inti=0;i<count;i++){
printf("Name:%s,Age:%d\n",students[i].name,students[i].age);
}
}
voidupdateStudent(structStudent*students,intcount,intindex,char*name,intage){
if(index>=0&&index<count){
strcpy(students[index].name,name);
students[index].age=age;
}
}
voiddeleteStudent(structStudent**students,int*count,intindex){
if(index>=0&&index<*count){
for(inti=index;i<*count-1;i++){
(*students)[i]=(*students)[i+1];
}
(*students)=(structStudent*)realloc(*students,(*count-1)*sizeof(structStudent));
(*count)--;
}
}
intmain(){
structStudent*students=NULL;
intcount=0;
addStudent(&students,&count,"John",20);
addStudent(&students,&count,"Jane",22);
printStudents(students,count);
updateStudent(students,count,0,"JohnDoe",21);
printStudents(students,count);
deleteStudent(&students,&count,1);
printStudents(students,count);
free(students);
return0;
}
2.
#include<stdio.h>
#include<string.h>
#defineMAX_TEXT1000
chartext[MAX_TEXT];
intcursor=0;
voidinsertText(char*str){
intlen=strlen(str);
memmove(text+cursor+len,text+cursor,MAX_TEXT-cursor-len);
strcpy(text+cursor,str);
cursor+=len;
}
voiddeleteText(intlen){
memmove(text+cursor,text+cursor+len,MAX_TEXT-cursor-len);
}
voidfindText(char*str){
intindex=strstr(text,str)-text;
if(index!=-1){
printf("Foundatposition:%d\n",index);
}else{
printf("Notfound\n");
}
}
intmain(){
strcpy(text,"Hello,world!");
cursor=7;
insertText("Clanguage");
printf("%s\n",text);
deleteText(10);
printf("%s\n",text);
findText("Clanguage");
return0;
}
五、材料分析题
该代码实现了一个单链表的创建和操作。具体功能如下:
1.定义了一个结构体`Node`,包含数据成员`data`和指向下一个节点的指针`next`。
2.`append`函数用
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年鹤岗市兴山区法检系统书记员招聘笔试参考题库及答案详解
- 2025年阳泉市矿区法检系统书记员招聘考试试题及答案详解
- 2025年浙江省丽水市法检系统书记员招聘笔试试题及答案详解
- 2025年郑州市上街区法检系统书记员招聘笔试试题及答案详解
- 2025年河南省漯河市法检系统书记员招聘笔试试题及答案详解
- 2026年渭南市临渭区住房和城乡建设局人员招聘笔试参考试题及答案详解
- 江苏徐州市贾汪区面向2026年乡村定向师范毕业生招聘教师40人笔试备考题库及答案详解
- 2026年淄博市周村区法检系统书记员招聘笔试参考试题及答案详解
- 2025-2026学年幼儿教学设计互评
- 2025年皮毛加工员(皮毛处理)试题及答案
- 鱼塘清淤合同协议书范本
- 焊工教学 培训课件
- 煤炭仓储物流项目投资估算
- JG/T 336-2011混凝土结构修复用聚合物水泥砂浆
- DZ/T 0197-1997数字化地质图图层及属性文件格式
- 互联网医院的医疗服务质量与伦理监管
- GB/T 13511.2-2025配装眼镜第2部分:渐变焦定配眼镜
- 物流中心视频监控方案
- 起重机应急预案演练记录
- 专升本英语高频词汇完全版
- 萨克斯-全球视角的宏观经济学-北京大学课件
评论
0/150
提交评论