收藏 分销(赏)

电大本科C语言程序设计A期末考试复习资料.doc

上传人:精**** 文档编号:9758616 上传时间:2025-04-06 格式:DOC 页数:19 大小:86.50KB
下载 相关 举报
电大本科C语言程序设计A期末考试复习资料.doc_第1页
第1页 / 共19页
电大本科C语言程序设计A期末考试复习资料.doc_第2页
第2页 / 共19页
点击查看更多>>
资源描述
本科《C语言程序设计A》复习资料 一、单选题 1.在每个C语言程序中都必须包含有这样一个函数,该函数的函数名为(A)。 A. main B. MAIN C. name D. function 2.每个C语言程序文件的编译错误分为(B)类。 A. 1 B. 2 C. 3 D. 4 3. 字符串"a+b=12\n"的长度为(B)。 A. 6 B. 7 C. 8 D. 9 4. 在switch语句的每个case块中,假定都是以break语句结束的,则此switch语句容易被改写为(D)语句。 A. forB. whileC. doD. if 5. 在下面的do-while循环语句中,其循环体语句被执行的次数为(C)。 int i=0; do i++; while(i<10); A. 8 B. 9 C. 10 D. 11 6. 将两个字符串连接起来组成一个字符串时,选用的字符串函数为(C)。 A. strlen() B. strcpy() C. strcat() D. strcmp() 7. 若用数组名作为函数调用的实参,传递给形参的是(A)。 A. 数组的首地址 B. 数组中第一个元素的值 C. 数组中全部元素的值 D. 数组元素的个数 8. 假定a为一个整数类型的数组名,整数类型的长度为4,则元素a[4]的地址比a数组的首地址大(C)个字节。 A. 4 B. 8 C. 16 D. 32 9. 假定s被定义为指针类型char *的变量,初始指向的字符串为"Hello world!",若要使变量p指向s所指向的字符串,则p应定义为(A)。 A. char *p=s; B. char *p=&s; C. char *p;p=*s; D. char *p; p=&s; 10. 从一个数据文件中读入以换行符结束的一行字符串的函数为(B)。 A. gets() B. fgets() C. getc() D. fgetc() 11.程序运行中需要从键盘上输入多于一个数据时,各数据之间默认使用(D)符号作为分隔符。 A.空格或逗号 B.逗号或回车 C.逗号或分号 D.空格或回车 12.逻辑表达式(x>0 && x<=10)的相反表达式为(A)。 A.x<=0 || x>10 B.x<=0 && x>10 C.x<=0 || x<=10 D.x>0 && x>10 13.当处理特定问题时的循环次数已知时,通常采用(A)循环来解决。 A.for B.while C.do-while D.switch 14.假定i的初值为0,则在循环语句“while(i<n) {s+=i*i; i++;}”中循环体被执行的总次数为(B)。 A.n-1 B.n C.n+1 D.n/2 15.假定一个二维数组的定义语句为“int a[3][4]={{3,4},{2,8,6}};”,则元素a[1][2]的值为(C)。 A.2 B.4 C.6 D.8 16.在下列选项中,不正确的函数原型格式为(C)。 A.int Function(int a); B.void Function (char); C.int Function(a); D.void int(double* a); 17.假定p是一个指向float型数据的指针,则p+1所指数据的地址比p所指数据的地址大(C)个字节。 A.1 B.2 C.4 D.8 18.假定有定义为“int m=7, *p;”,则给p赋值的正确表达式为(B)。 A.p=m B.p=&m C.*p=&m D.p=*m 19.假定指针变量p定义为“int *p=malloc(sizeof(int));”,要释放p所指向的动态存储空间,应调用的函数为(A)。 A.free(p) B.delete(p) C.free(*p) D.free(&p) 20.C语言中的系统函数fopen()是( D)一个数据文件的函数。 A.读取 B.写入 C.关闭 D.打开 21. C语言源程序文件的缺省扩展名为(D)。 A. cpp B. exe C. obj D. C 22.设x和y均为逻辑值,则x&&y为真的条件是(A)。 A. 它们均为真 B. 其中一个为真 C. 它们均为假 D. 其中一个为假 23. 在下列的符号常量定义中,正确的定义格式为(C)。 A. #define M1 B. const int M2 20 C. #define M3 10 D. const char mark 24. for循环语句能够被改写为(D)语句。 A. 复合 B. ifC.switchD. while 25. 在下面的一维数组定义中,错误的定义格式为(C)。 A. int a[]={1,2,3} B. int a[10]={0} C. int a[] D. int a[5] 26.下面的函数原型声明中存在语法错误的是(C)。 A. AA(int a, int b) B. AA(int, int) C. AA(int a; int b;) D. AA(int a, int) 27. 假定a为一个数组名,则下面存在错误的表达式为的(B)。 A. a[i] B. *a++ C. *a D. *(a+1) 28. 假定有定义为“int a[10], x, *pa=a;”,若要把数组a中下标为3的元素值赋给x,则不正确的赋值为(D)。 A. x=pa[3] B. x=*(a+3) C. x=a[3] D. x=*pa+3 29.char类型的长度为(A)个字节。 A. 1 B. 2 C. 3 D. 4 30. 向一个二进制文件中写入信息的函数为(D)。 A. fgets() B. fputs() C. fread() D. fwrite() 31. 由C语言目标文件连接而成的可执行文件的缺省扩展名为(B)。 A. cpp B. exe C. obj D. c 32. 设有两条语句为“int a=12; a+=a*a;”,则执行结束后,a的值为(C)。 A. 12 B. 144 C. 156 D. 288 33. 带有随机函数调用的表达式rand()%20的值在(C)区间内。 A. 1~19 B. 1~20 C.0~19 D. 0~20 34. for循环语句“for(i=0; i<n; i+=2) S;”中循环体S语句被执行的次数为(A)。 A. (n+1)/2 B. n/2+1 C. n/2-1 D. n-1 35. 在下列的字符数组定义中,存在语法错误的是(D)。 A. char a[20]="abcdefg"; B. char a[]="x+y=55."; C. char a[15]={'1','2'}; D. char a[10]='5'; 36. 若有一个函数原型为“double *function()”,则它的返回值类型为(B)。 A. 实数型 B. 实数指针型 C. 函数指针型 D. 数组型 37. 在C语言中,所有预处理命令都是以(B)符号开头的。(B) A. * B. # C. & D. @ 38. 假定整数指针p所指数据单元的值为30,p+1所指数据单元的值为40,则执行*p++后,p所指数据单元的值为(A)。 A. 40 B. 30 C. 70 D. 10 39. 若要使p指向二维整型数组a[10][20],则p的类型为(D)。 A. int * B. int ** C. int *[20] D. int(*)[20] 40. 表示文件结束符的符号常量为(C) A. eof B. Eof C. EOF D. feof 41. C语言程序中的基本功能模块为(D)。 A.表达式 B.标识符 c.语句 D.函数 42.逻辑表达式(x>0||y==5)的相反表达式为(B)。 A.x<=O||y!=5 B.x<=O&&y!=5 C.x>O||y!=5 D.x>O&&y==5 43.循环体至少被执行一次的循环语句为 (C)。 A.for B.while C.do-while D.任一种循环 44.假定 n的值为5,则表达式n++的值为(B)。 A.6 B.5 C.4 D.7 45.假定一个二维数组的定义为"int a[3][4]={{3,4},{2,8,6}}号",则元素a[2][O]值为(A)。 A.0 B.2 C.4 D.6 46.假定一个函数原型为"char *func(int n)",则该函数的返回类型为(D)。 A. int B. int* c.char D.char* 47.假定a为一个字符数组名,则元素a[i]的指针访问方式为(B)。 A.a+i B.*(a+i) C.&a+i D.*a+i 48.假定有语句为"int *p=calloc(10+20,sizeof(int)),则p所指向的动态数组中所包含的元素个数为(C)。 A.10 B.20 c.30 D.40 49.十进制数 50表示成符合C语言规定的八进制数为(D)。 A. 20 B.32 C.62 D.062 50.若要以读和写两种操作方式打开一个二进制文件,当文件不存在时返回打开失败信息,则选用的打开方式字符串为(C)。 A."r+" B."ab+" C. "rh+" D."wb+" 二、填空题 1.在一个C语言程序文件中,若要包含另外一个头文件或程序文件,则应使用的预处理命令为(#include ) 2.用于从键盘上为变量输入值的标准输入函数的函数名为(scanf) 3.假定一个枚举类型的定义为"enum RA{ab,ac,ad,ae};",则ac的值为(1) 4. double类型的长度为(8) 5.执行"int x=45, y=13; printf("%d",x/y);"语句序列后得到的输出结果为(3) 6.把表达式x=x+y转换成复合赋值表达式为(x+=y) 7.假定x的值为5,则执行"a=((!x)?10:20);"语句后a的值为(20) 8.假定一维字符指针数组的定义为"char* a[8];",则该数组占用的存储空间的字节数为(32) 9.假定二维数组的定义为"double a[M][N];"则数组元素的行下标取值范围在(0~M-1)之间 10.空字符串的长度为 (0) 11.在所有函数定义之外定义的变量,若没有被初始化则系统隐含对它所赋的初值为(0) 12.若p指向x,则(*p)与x的表示是等价的。 13. 直接访问表达式(*fp).score所对应的间接访问表达式为(fp->score) 14.一个函数定义由 函数头_和函数体两部分组成。 15. 执行“printf("%c",'F'-2);”语句后得到的输出结果为 D。 16.int类型的长度为4 。 17. 表达式(float)25/4的值为 6.25。 18.若x=5,y=10,则x<=y的逻辑值为 1(或真) 。 19. 作为语句标号使用的case和default只能用于 switch 或开关 或分情况_语句的定义体中。 20. 在程序中执行到return 或返回 语句时,将结束所在函数的执行过程,返回到调用该函数的位置。 21. 假定二维数组的定义为“char a[M][N];”,则该数组所含元素的个数为M*N。 22. 存储字符'a'需要占用存储器的_1_个字节空间。 23. 用于存储一个长度为n的字符串的字符数组的长度至少为_n+1_。 24. 假定p所指对象的值为25,p+1所指对象的值为46,则执行表达式(*p)++后,p所指对象的值为_26_。 25. 假定p是一个指向整数对象的指针,则用*p表示该整数对象。 26.假定一个结构类型的定义为“struct B{int a[5]; char* b;};”,则该类型的理论长度为_24_。 27. C语言中的每条复合语句以_ }(或右花括号)作为结束符。 28. 在#include命令中所包含的文件,可以是头文件,也可以是_程序_文件。 29. 十进制数35对应的八进制数为43 。 30. 假定x=5,则表达式2+x++的值为 7 。 31.增量表达式++y表示成赋值表达式为y=y+1。 32.若x=5,y=10,则x>y的值为0(假)。 33. 假定二维数组的定义为“int a[3][5];”,则该数组所含元素的个数为15。 34. 执行“typedef int ABC[10];”语句把ABC定义为具有10个整型元素的_数组_类型。 35. strcat()函数用于连接两个字符串。 36.假定p所指对象的值为25,p+1所指对象的值为46,则*p++的值为 25 。 37. 若要把一个整型指针p转换为字符指针,则采用的强制转换表达式为(char*)p。 38. NULL是一个符号常量,通常作为空指针值,它对应的值为0 。 39. 假定要动态分配一个类型为struct Worker的对象,并由r指针指向这个对象,则使用的表达式为 struct Worker* r=malloc(sizeof(struct Worker))。 40. 在一个C语言程序文件中,若要包含另外一个头文件或程序文件,则应使用的预处理命令为#include。 41. 用于从键盘上为变量输入值的标准输入函数的函数名为scanf。 42. 假定一个枚举类型的定义为“enum RA{ab,ac,ad,ae};”,则ac的值为_1 。 43.double类型的长度为_8_。 44. 执行“int x=45,y=13;printf("%d",x/y);”语句序列后得到的输出结果为_3_。 45. 表达式x=x+y表示成复合赋值表达式为x+=y。 46. 假定x=5,则执行“a=(!x? 10: 20);”语句后a的值为_20_。 47. 假定一维字符指针数组的定义为“char* a[8];”,则该数组占用的存储空间的字节数为_32_。 48. 假定二维数组的定义为“double a[M][N];”,则每个数组元素的行下标取值范围在_0~M-1之间。 49. 空字符串的长度为_0_。 50. 在函数外定义的变量,若没有被初始化则系统隐含对它所赋的初值为 0_。 51. 若p指向x,则*p与x的表示是等价的。 52. 与结构成员访问表达式(*fp).score等价的表达式为fp->score 。 53.执行“printf("%c",'A'+2);”语句后得到的输出结果为_C_。 54.short int类型的长度为_2_。 55. 用类型关键字表示十进制常数3.26f的类型为 float 。 56. 假定y=10,则表达式++y*3的值为_33_。 57. 逻辑表达式(x==0 && y>5)的相反表达式为(x!=0 || y<=5) 或:(x || y<=5)。 58.若x=5,y=10,则x!=y的逻辑值为_1(真,true)_。 59. 假定二维数组的定义为“int a[3][5];”,则该数组所占存储空间的字节数为_60_。 60. 使用“typedef char BB[10][50];”语句定义_BB_为含有10行50列的二维字符数组类型。 61. 字符串"a:\\xxk\\file.txt"的长度为_15_。 62.假定p所指对象的值为25,p+1所指对象的值为46,则*++p的值为_46_。 63. 假定一个数据对象为int*类型,则指向该对象的指针类型为_int**_。 64.假定一个结构类型的定义为 “struct A{int a,b; A* c;};”,则该类型的理论长度为_12_。 65. 假定要访问一个结构对象x中的数据成员a,则表示方式为_x.a_。 三、写出下列每个程序运行后的输出结果 1. #include<stdio.h> void main() { int i,j,k=0; for(i=0; i<5; i++) for(j=i; j<5; j++) k++;; printf("%d\n",k); } 运行结果:15 2. #include<stdio.h> void main() { int x=20; int i=2; while(i<x) { if(x%i==0) {printf("%d",i); x/=i;} i++; } } 运行结果:2 5 3. #include<stdio.h> void main() { int a[8]={70,63,54,95,40,75,90,66}; int i, s=0; for(i=0; i<8; i++) if(a[i]>=70 && a[i]<=90) s+=a[i]; printf("s=%d\n",s); } 运行结果:s=235 4. #include<stdio.h> int WF(int x, int y) { x=x+y; y+=x; return x+y; } void main() { int x=3, y=5; printf("%d\n",WF(x,y)); } 运行结果: 21 5. #include<stdio.h> int LA(int *a, int n) { int i,s=0; for(i=0;i<n;i++) s+=a[i]; return s; } void main() { int a[5]={1,2,3,4,5}; int b=LA(a,5)+LA(a+1,3); printf("b=%d\n",b); } 运行结果: b=24 6. #include<stdio.h> void main() { int x=5; switch(2*x-1) { case 4: printf("%d ",x); break; case 7: printf("%d ",2*x); break; case 10: printf("%d ",3*x); break; default: printf("%s","default"); } printf("%s\n","switch end."); } 运行结果:default switch end. 7. #include<stdio.h> void main() { int f1,f2,i; f1=1; printf("%d ",f1); for(i=2;i<=5;i++) { f2=3*f1+1; printf("%d ",f2); f1=f2; } printf("\n"); } 运行结果: 1 4 13 40 121 8. #include<stdio.h> void main() { int a[10]={12,39,26,41,55,63,72,40,83,95}; int i, i1=0, i2=0; for(i=0;i<10;i++) if(a[i]%2==1) i1++; else i2++; printf("%d %d\n",i1,i2); } 运行结果:6 4 9. #include<stdio.h> #include<string.h> void main( ) { char s[15]="567891234"; int i, n=strlen(s) ; for(i=0; i<n/2; i++) { char c=s[i]; s[i]=s[n-1-i]; s[n-1-i]=c; } printf("%s\n",s); } 运行结果:432198765 10. #include<stdio.h> int LB(int *a, int n) { int i,s=1; for(i=0;i<n;i++) s*=*a++; return s; } void main() { int a[]={1,2,3,4,2,4,5,2}; int b=LB(a,4)+LB(a+3,3); printf("b=%d\n",b); } 运行结果: b=56 11. #include<stdio.h> void main() { int i, s=0; for(i=1;;i++) { if(s>30) break; if(i%2==0) s+=i; } printf("s=%d\n",s); } 运行结果:s=42 12. #include<stdio.h> void main() { int a[9]={36,25,48,24,55,40,18,66,20}; int i, b1, b2; b1=b2=a[0]; for(i=1; i<9; i++) { if(a[i]>b1) b1=a[i]; if(a[i]<b2) b2=a[i]; } printf("%d %d\n",b1,b2); } 运行结果:66 18 13. #include<stdio.h> void SB(char ch) { switch(ch) { case 'A': case 'a': printf("WW "); break; case 'B': case 'b': printf("GG "); break; default: printf("BB "); break; } } void main() { char a1='a',a2='B',a3='f'; SB(a1);SB(a2);SB(a3); printf("\n"); } 运行结果:WW GG BB 14. #include<stdio.h> #define M 6 void main() { int i,x; int a[M]={10,15,22,37,46,58}; for(i=0; i<M/2; i++) {x=a[i]; a[i]=a[M-1-i]; a[M-1-i]=x;} for(i=0; i<6; i++) printf("%d ",a[i]); printf("\n"); } 运行结果:58 46 37 22 15 10 15. #include<stdio.h> struct Worker { char name[15]; int age; float pay; }; void main() { struct Worker x={"wanghua",52,2350}; struct Worker y, *p; y=x; p=&x; printf("%d %7.2f\n",y.age+p->age, p->pay+20); } 运行结果:104 2370.00 16. #include<stdio.h> void main() { int i,s=0; for(i=1;i<6;i++)s+=i*i; printf(“s=%d\n”,s);} 运行结果: s=55 17. #include<stdio.h> #define N 6 void main() { int i,a[N]={2,5,8,10,15,21}; for(i=0; i<N; i++) if(a[i]%5) printf("%d ",a[i]); printf("\n"); } 运行结果: 2 8 21 18. #include<stdio.h> #include<string.h> void main() { int i; unsigned int len; char* a[5]={"student","worker","cadre","soldier","zzeasan123"}; len=strlen(a[0]); for(i=1; i<5; i++) if(strlen(a[i])>len) len=strlen(a[i]); printf("%d\n",len); } 运行结果:10 19. #include<stdio.h> void main() { int a,b; for(a=2,b=3; b<20;) { printf("%d %d ",a,b); a=a+b; b=a+b; } printf("%d %d\n",a,b); } 运行结果:2 3 5 8 13 21 20. #include<stdio.h> void LE(int* a, int* b) { int x=*a; *a=*b; *b=x; } void main() { int x=15, y=26; printf("%d %d\n",x,y); LE(&x,&y); printf("%d %d\n",x,y); } 运行结果:15 26 26 15 21. #include<stdio.h> void main() { int i, s1=0, s2=0; for(i=0;i<10;i++) if(i%2) s1+=i; else s2+=i; printf("%d %d\n",s1,s2); } 运行结果: 25 20 22. #include<stdio.h> const int M=20; void main() { int i=2; while(1) { if(i>M/2) break; if(M%i==0) printf("%d ",i); i++; } printf("\n"); } 运行结果:2 4 5 10 23. #include<stdio.h> int a[6]={4,5,6,15,20,12}; void main() { int i,s1,s2; s1=s2=0; for(i=0; i<6; i++) { switch(a[i]%2) { case 0: s2+=a[i];break; case 1: s1+=a[i];break; } } printf("%d %d\n",s1,s2); } 运行结果:20 42 24. #include<stdio.h> void main() { int a[3][3]={{3,5,7},{9,11,13},{6,8,20}}; int i,*p=&a[0][0]; for(i=0;i<9;i++) { if(*p>10) printf("%d ",*p); p++; } printf("\n"); } 运行结果:11 13 20 25. #include<stdio.h> #include<string.h> struct Worker { char name[15]; int age; float pay;}; void main() { struct Worker x; char *t="liouting"; int d=38; float f=400; strcpy(x.name,t); x.age=d; x.pay=f; x.age++; x.pay*=2; printf("%s %d %6.2f\n",x.name,x.age,x.pay); } 运行结果: liouting 39 800.00 26. #include<stdio. h> void main() { int i,j ,k==0; for ({i=O;i<5;i++) for(j=i;j<5;j++) k++;; printf("%d\n",k) ; } 运行结果:15 27. #include<stdio. h> void main() { int x=20; int i=2; while(i<x) { if(x%i==0) {printf("%d",i); x/=i;} i++; }} 运行结果:25 28. #include<stdio. h> void main() { int a[8]={76,63,54,95,40,75,90,66}; int i, s=0; for(i=0;i<8;i++) if(a[i]>=70 && a[i]<=90) s+=a[i]; printf("s=%d\n",s) ; } 运行结果:s=241 29. #include<stdio. h> int WF(int x , int y) { x=x+y; y+=x; return x+y; } void main() { int x=3 , y=8; printf("%d\n" ,WF(x,y));} 运行结果:30 30. #include<stdio. h> int LA
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手

当前位置:首页 > 教育专区 > 远程教育/电大

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服