C语言期中考试卷1,4.pdf
《C语言期中考试卷1,4.pdf》由会员分享,可在线阅读,更多相关《C语言期中考试卷1,4.pdf(16页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、C语言期中考试卷一、选择题。I、c 语言程序是由J1 C L 组成的。1 A)子程序B)过程C)函数D)主程序和子程序2、凡在函数内未指定存储类型的变量,其隐含的存储类型为A。2 A)aut o(自动)B)s t at i c(静态)C)ex t ern(外部)D)reg i s t er(寄存器)3、已知char型变量ch的值为大写英文字母,下列表达式中值为逻辑真的是BD。3 A)A,=ch=Z,B)(、A,=ch)C)(ch=A)&(ch=A,)|(ch=Z,)4、定 义 i nt a=5;float x=6.5;那么表达式(l?a I x)的 数 据 类 型 是 上。4 A)i nt B
2、)float C)double D)不确定5、设已定义整型变量x、y,则下面程序的输出为A。x=1 5;y=4 7;p ri nt f(%d+x);p ri nt f(、%x n”,y+);5 A)1 6 2 f B)1 5 2 f C)1 5 3 0 D)1 6 3 06、行以下语句后,c 的二进制值是。char a=3,b=6,c;c=a-b 2;6 A)0 0 0 1 1 1 0 0 B)0 0 0 1 1 0 1 1 C)0 0 0 1 1 0 0 0 D)0 0 0 1 0 1 0 07,执行下列语句后,x的 值 是 C。i nt i,j,x;for(i=0,j=8;i j;i+,j
3、)x=i+j;7 A)0 B)4 C)8 D)3 28、设有枚举类型定义:enum color red=3,y ellow,blue=1 0,w hi t e,black;则枚举量 bi ack的 值 是 B。8 A)7 B)1 2 C)1 4 D)1 59、设有以下说明,则下面不正确的叙述是A。uni on dat ai nt i;char c;float f;a;9 A)a 可以作为函数的参数 B)a 和它各成员的地址相同0 a 所占的内存长度等于其成员f 的长度 D)不能直接对a 进行赋值1 0、运行下列程序:当键盘输入为4 5 口口口1 2 3 人并回车后,显 示 C .B。mai n
4、()i nt x;float y;s canf(、%f%3 s ,&y,x);p ri nt f(、%f,%s n”,y,x);1 0 A)无定值 B)1 2 3.0 0 0 0 0 0 C)4 5.0 0 0 0 0 0 D)4 5 1 1 A)口 B)1 2 3 0 1 2 3%D)无定值1 1、下列程序的输出结果为C。mai n()i nt i;for(i=l;i=5;i+)i f(i%2)p ri nt f(*)els e cont i une;p ri nt f;p ri nt f(s nzO ;1 2 A)*#s B)C)*#*#*#s D)*#*#s1 2、下面程序的输出结果是A
5、 o#i nclude i nt x,y;voi d done()i nt a=5,b=3;x=a*b;y=a/b;mai n()i nt a=9,b=4;x=a+b;y=a-b;done();p ri nt f(%d,%d nz z,x,y);1 3 A)1 5,1 B)1 3,5 C)1,1 5 D)5,1 31 3、假设已定义char a 2 0 ;和 char*p;下面的赋值语句中,正确的是C。1 4 A)a=H ow are y ou!;B)a 2 0 =H ow are y ou!”;C)p=H ow are y ou!”;D)*p=H ow are y ou!”;1 4、执行下列
6、程序,输入为1 时 的 输 出 结 果 为,输入为3时 的 输 出 结 果 为 omai n()i nt x;s canf&x);s w i t ch(x)cas e 1:p ri nt f(u%d,z,+x);cas e 2:p ri nt f(u%d,z,+x);cas e 3:p ri nt f(%d,z,+x);cas e 4:p ri nt f(、d n,+x);break;)1 5 A)1 B)2 C)1 2 3 4 D)2 3 4 5 1 6 A)3 B)4 C)3 4 D)4 51 5、下列程序的输出结果为&L o#i ncludei nt x=5,y=7;voi d s w
7、ap ()i nt z;z=x;x=y;y=z;mai nO i nt x=3,y=8;s w ap ();p ri nt f(%d,%d n,x,y);1 7 A)3,8 B)8,3 C)5,7 D)7,51 6、阅读程序,选择正确的输出结果。#i ncludemai nO i nt a=2 0,b=1 0;char*format=a=%d n/,;a/=b+l;p ri nt f(format,a);输出 a-Aa=2 0;b=1 0;a%=b+l;p ri nt f(format,a);输出 a=B)1 8 A)1 B)3 C)0 D)2 1 9 A)0 B)9 C)1 D)1 11 7
8、、设有定义i nt x=5;下列表达式的值是 D o(i)x&、0 (i i)x x (i i i)!x (i v)!x|x 2 0 A)(i)0 (i i)1 (i i i)1 (i v)5 B)(i)-1 (i i)0 (i i i)5 (i v)0C)(i)1 (i i)5 (i i i)0 (i v)1 D)(i)5 (i i)-1 (i i i)1 (i v)51 8、阅读下面程序。若 使 用 C 替换程序中的cont i nue;语句来改写程序,可保持程序功能不变;若将cont i nue;替 换 为 A,则程序的输出结果发生变化。mai n()i nt i=0;w hi le(+
9、i 1 0)i f(i=5)cont i nue;p ri nt f(、%d n,i);)2 1 A)break;B);/*空语句*/0+i;D)ex i t(0);2 2 A)/*空白*/B)p ri nt f(、%d n,+i);els e C)i=6 D)i+,p ri nt f(、%d n,i+)1 9、设有如下定义,则 表 达 式 的 值 为 C ,的 值 为 D。s t at i c i nt a 3 3 =1,2,3,4,5,6,7,8,9;s t at i c i nt (*p)3 =a;s t at i c i nt *q 2 =a l,a 2 ;2 3 A)4 B)5 C)
10、6 D)7 2 4 A)6 B)7 C)8 D)92 0、设有如下定义和语句,则这些语句执行后,s i 和 s 2 的值分别为 B o defi ne M(x,y)x*yi nt a=3,b=2,s i,s 2;s l=M(a+b,a-b);s 2=M(a-b,a+b);2 5 A)5,5 B)7,-1 C)5,-1 D)7,52 1、若已定义a 为 char型变量,则 D 是对指针变量p的正确说明和初始化。2 6 A)char*p=a;B)char*p 二*a;C)char p=&a;D)char*p=&a;2 2、执行以下程序段后,x的 值 为 C os t at i c i nt a =
11、3,5,7,9;i nt i,x=l;for(i=0;i a ge);B)s c a n f(%dz z,&pu p 0.a ge);C)s c a n f(%sz,pu p 0.n a me);D)s c a n f(%dz z,&(p-s ex);24、设有以下说明语句,则 语 句 是 合 法 的。s t r u c t per s on c ha r n a me 15;in t a ge;fl oa t w a ge;t ea c her;29 A)per s on+;B)per s on.a ge+;C)get s (t ea c her,n a me);D)t ea c her-w
12、 a ge=1000.00;25、设有定义c ha r *a,b 5 1:以下语句中对a,b可正确输入或赋值的是D。3 0 A)s c a n f*a);B)b=a;C)b=ABC;D)a=ABCz z;26、以下程序的输出结果是C oin t i;for(i=0;i 10;i+)if(i%3=0)pr in t f i);el s e if(i%5=0)pr in t f i);3 1 A)0 3 6 9 5 B)0 0 3 5 6 9 0 0 3 5 6 9 D)0 3 6 9 0 527、以下程序段的输出结果为 A os t a t ic c ha r a =l a n gu a ge,
13、b =pr ogr a mez z;in t i;for(i=0;i 8;i+)if(a i=b i)pr in t f a i);3 2 A)pr ogr a me B)l a n u g C)l a n gu a ge D)ga e28、执行以下程序段后,m的 值 为 D os t a t ic in t a 2 2=0,1,4,5;in t m;m=a l a 0 0*a l a 0 l;3 3 A)0 B)4 C)5 D)2029、以下程序段的输出结果为 C os t a t ic c ha r a=ABC;c ha r *p;for (p=a;p a+3;p+)pr in t f(v
14、%sz z,p);A)ABC B)BCC C)ABCBCC D)ABBCCC3 0、以下程序的输出结果为_ L oma in()in t *c ha n ge_ pt r();in t *pt r,b 3=3,2,1;pt r=b;pt r=c ha n ge_ pt r(pt r);pr in t f*pt r);in t *c ha n ge_ pt r(in t *p)P+=l;r et u r n (p);)3 5 A)1 B)2 C)3 D)43 1、以下程序的输出结果为 B ovoid pl u s()in t a=0;s t a t ic in t b=0;pr in t f a
15、+b);a+;b+;)ma in()in t i;for(i=0;i 3;i+)pl u s();3 5 A)0 0 0 B)0 1 2 C)0 2 4 D)0 1 43 2、阅读以下程序,该程序的输出结果为B 。ma in()c ha r *s=x y z ,*t 二、x z y ;if(*s=*t)pr in t f(、l,);el s e pr in t f(、2,);if(!s t r c mp(s,t)pr in t f(3 nz z);el s e pr in t f(4 n,z);3 7 A)1,3 B)1,4 C)2,3 D)2,43 3、阅读以下程序,该 程 序 的 输 出
16、结 果 为 程 oma in()in t a 2 2,i,j;for(i=0;i 2;i+)for(j=0;j 2;j+)a i j=i*2+j;for(i=0;i 2;i+)for(i=0;j 2;j+)pr in t f(%dz z,a j i);pr in t f(、n);)3 8 A)1 3 B)0 1 C)1 2 D)2 4 2 3 0 33 4、阅读以下程序,当输入字符序列AB#CD#in c l u d evoid r ev()c ha r c;c=get c ha r ();if(c=#,)pr in t f(%cz z,c);el s e r ev();pr in t f c
17、);ma in()r ev();3 9 A)AB#CD B)#ABCD C)#CD3 5、下面函数与 D 是等价的。fl oa t s(fl oa t x,fl oa t d el t a)fl oa t y,z=0.0;for(y=l.O;y d el t a;y/=x)z+=y;r et u r n z;4 0 A)fl oa t s(fl oa t x,fl oa t d el t a)fl oa t y;for(y=l.0;y d el t a;y/=x)r et u r n s(x,d el a t a)+y;C)fl oa t s(fl a t x,fl oa t d el t a
18、)fl oa t z=0.0,y=l.0;w hil e(y d el t a);r et u r n z;D)fl oa t s (fl oa t x,fl oa t d el t a)fl oa t z=0.0,y=l.0;for(;y d el t a;)z+=y;y/=x;r et u r n z;二、请正确填充下面的函数或程序的划线部分,使其完成所要求的功能。1、下面程序完成以下函数f(x,y)的计算。x2f(X,y)=-/.sin2(x-y)+2sin(x-y)+3sin2(x-y)#in c l u d e#in c l u d e fl oa t fu n l(fl oa t
19、x)fl oa t fl;fl=x*x+s qr t (l+J j J _);r et u r en(fl);ma in()fl oa t x,y,f;s c a n f&x,&y);f=x*x/fu n l(2 );pr in t f(f=%fn,f);2、下面函数d t ox(n,s)将无符号十进制整数n 转换成十六进制形式并存于字符串s中,其中调用函数r ever s e(s)将字符串s 逆置(例如字符串DCBA是字符串ABCD的逆置)。#in c l u d e void d t ox(u n s ign ed n,c ha r s )in t h,i=0;d oh=n%16;n=n/
20、16;s i+=(h=9)?h+,0包;w hil e(n!=0);s i=4 ;r ever s e(s);void r ever s e(c ha r a )c ha r c,i,j;for (i=0,i=s t r l en(a)-l;5 ;i+,j-)c=a i ;6 :a j =c;)3、fin d(t,s)函数用来确定字符串t 是否为s的子串,如不是,函数返回0,否则返回t 在s中第1 次出现时其第一个字符在s中的位置(例如fin d(、a b,a b ed)返回值为1),fin d (t,s)I L L in t i=0,j=0;w hil e(t i!=8 !=0)if(t i
21、+!=s j+)i=9 ;i=0;if(t i=0)r et u r n 10:r et u r n 0;4、已知正文文件a b c.t x t,统计该文件中词的个数并求出最长词的长度。一个词与另一个词之间留空符、制表符、换行符分隔。#in c l u d e ma in()F I L E 11;c ha r c h;in t w or d=0;/*存放词的个数*/in t ma x l en t h=O;/*存放最长词的长度*/in t l en t h=O;/*存放当前词的长度*/in t fl a g=O;/*fl a g=l 表示当前字符在某词中,fl a g=0表示当前字符不在某词中
22、*/if(fp=fopen(12X,r)=N U L L)pr in t f(Ca n n ot O pen t his fil e!nz,);ex it (0);c h=fget c(fp);w hil e(c h!=E O F)if(c h二 二|c h=二 t|13 )if(fl a g=l)fl a g=0;if(l en t h ma x l en t h)14 ;el s e if(fl a g=0)fl a g=l;l en t h=l;15 ;/*统计词的个数*/:J el s e 16 ;/*统计当前词的长度*/c h=fget c(fp);/*en d of w hil e
23、*/fc l os e(fp);pr in t f(w or d=%d,ma x l en t h二%d n”,w or d,ma x l en t h);5、下面程序处理两个一位自然数的加、减、乘、除四则运算命令。例如程序提示后输入5+4,程序马上输出二9。按下,键结束程序。请补充完整。(get c heO 函数是读入一个从键盘键入的字符,并将该字符显示在屏幕上)。#in c l u d e 17 Q U I T(x)x=Qz!x=、qma in()in t a,b;c ha r c,d;d o pr in t f(I n pu t:,z);d=get c he();if(d =0,&d =
24、Oz&d b)&+n;5 A)1 B)2 C)3 D)46、已知各变量的类型如下,则以下符合C语 言 语 法 的 表 达 式 是 oi n t i=8,a,b;d oubl e x=l.4 2,y=5.2;6 A)a+=a-=(b=4)*(a=3)B)a=a*3=2 C)x%(-3)D)y=f l oat(i)7、以下程序的运行结果是B o#i n c l ud e m ai n()i n t m=5;i f (m+5)pri n tf (、%d n ,m);e l se pri n tf (%d nz,m+);7 A)7 B)6 C)5 D)48、以下程序的运行结果是Lo#i n c l u
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 期中 考试卷
限制150内