(完整版)C语言程序设计阅读程序题库及答案_第1页
(完整版)C语言程序设计阅读程序题库及答案_第2页
(完整版)C语言程序设计阅读程序题库及答案_第3页
(完整版)C语言程序设计阅读程序题库及答案_第4页
(完整版)C语言程序设计阅读程序题库及答案_第5页
已阅读5页,还剩31页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、阅读程序题导读:学会阅读程序对于初学者来说很重要,一方面可以巩 固所学的语法知识,另一方面通过阅读别人写好的程序来打 开自己的思路,就所谓见多识广。读者通过阅读理解程序, 从给出的四个备选参考答案中,选择程序的正确输出。如果 选择有误,就要认真分析原因,是概念方面的错误还是对程 序逻辑理解不对,从而加深对语法规则的理解,提高程序设 计能力。程序设计语言是开发程序的一个工具,学习语言的 目的是为了编写程序来解决实际问题,所以特别提倡通过实 际上机来检验备选答案,增强动手能力。习题基本上是按照 教材的章节来安排的,读者可以根据学习的进度选择部分习 题。【 2.1】以下程序的输出结果是 。 main

2、( ) float a ;a=1/100000000;printf("%g" , a);A) 0.00000e+00 B) 0.0 C) 1.00000e-07 D) 0【2.2】下面程序的输出结果是 。#include <stdio.h>main( ) int x=10 ; int x=20 ; printf ("%d ,", x) ; printf("%dn", x) ; A) 10 ,20 B) 20,10 C) 10,10 D) 20,20【2.3】以下程序的输出结果是 。main() unsigned int n

3、 ; int i=-521 ; n=i; printf("n=%un",n) ;A) n=-521 B) n=521 C) n=65015 D) n=1021701032.4】以下程序的输出结果是 。 main( ) int x=10, y=10 ;n", x,;y)A) 10 10 B) 9 9 C) 9 10 D) 10 9【2.5】以下程序的输出结果是 _main() int n=1 ;printf("%d %d %dn",n,n+,n-) ;A) 1 1 1 B) 1 0 1 C) 1 1 0 D) 1 2 1【2.6】以下程序的输出结

4、果是 _main() int x=0x02ff,y=0x0ff00 ;printf("%dn",(x&y)>>4|0x005f) ;A) 127 B) 255 C) 128 D) 1【2.7】以下程序的输出结果是 _main() int a=1 ;char c='a';float f=2.0 ;printf("%dn",(!(a=0),f!=0&&c='A') ;A) 0 B) 1【2.8】下面程序的输出结果是main() int a=1 , i=a+1 ;do a+ ;while( !

5、i+ > 3) ;printf("%dn",a) ;A) 1 B) 2 C) 3 D) 4【2.9】下面程序的输出结果是main() int a=111 ;a=aA00;printf("%d,%on",a,a) ;A) 111,157 B) 0,0 C) 20,24 D) 7,7【2.10】下面程序的输出结果是 。main() char s12= "a book" ; printf("%.4s",s) ;A) a book! B) a book!< 四个空格C) a bo D) 格式描述错误,输出不确定

6、【2.11】下面程序的输出结果是 。main() int a,b ; scanf("%2d%3d",&a,&b) ; printf("a=%d b=%dn",a,b) ;A) a=12 b=34 B) a=123 b=45 C) a=12 b=345 D) 语句右错误【2.12】以下程序段的输出结果是 。 int a=10,b=50,c=30 ; if(a>b)a=b;b=c;c=a;printf("a=%d b=%d c=%dn",a,b,c) ; A) a=10 b=50 c=10 B) a=10 b=30

7、c=10 C) a=50 b=30 c=10 D) a=50 b=30 c=50main()【2.13】以下程序的输出结果是。 int a=0,b=1,c=0,d=20 ;if(a) d=d-10 ;else if(!b)if(!c) d=15 ;else d=25;printf("d=%dn",d) ;A) d=10 B) d=15 C) d=20 D) d=25【2.14】下面程序的输出结果为。main() int a=1,b=0 ; switch(a) case 1: switch (b) case 0: printf("*0*") ; break

8、; case 1: printf("*1*") ; break; case 2: printf("*2*") ; break;A)*0*B)*0*2*C) *0 *1*2*D) 有语法错【 2.15】以下程序的输出结果是 。 main() char *s="12134211" ;int v1=0,v2=0,v3=0,v4=0,k ; for(k=0 ;sk ; k+) switch(sk) case '1': v1+ ;case '3': v3+;case '2': v2+;defaul

9、t: v4+ ;printf("v1=%d, v2=%d, v3=%d, v4=%dn",v1,v2,v3,v4) ; A) v1=4,v2=2,v3=1,v4=1 B) v1=4,v2=9,v3=3,v4=1C) v1=5,v2=8,v3=6,v4=1 D) v1=4,v2=7,v3=5,v4=8【2.16】下面程序的输出是 。 main() int x=1,y=0,a=0,b=0 ; switch(x) case 1: switch(y) case 0: a+ ;break; case 1: b+; break;case 2: a+; b+ ; break;printf

10、("a=%d,b=%dn",a,b) ;A) a=2,b=1 B) a=1,b=1 C) a=1,b=0 D) a=2,b=2【2.17】下面程序的输出是 。main() int num=0 ; while(num<=2) num+ ; printf("%dn",num) ;A) 1 B) 1 C) 1 D) 12 2 23 34【2.18】下面程序的输出结果是 main() int a=1,b=0 ;do switch(a) case 1: b=1 ;break;case 2: b=2; break;default : b=0 ;b=a+b;wh

11、ile(!b) ; printf("a=%d,b=%d",a,b) ;A) 1,2 B) 2,1 C) 1,1 D) 2,2【2.19】从键盘上输入 "446755" 时,下面程序的输出是 #include <stdio.h>main() int c ; while(c=getchar()!='n') switch(c -'2') case 0:case 1: putchar(c+4);case 2: putchar(c+4); break;case 3: putchar(c+3); default: putc

12、har(c+2) ; break; printf("n") ;A) 888988 B) 668966 C) 88898787 D) 66898787【2.20】下面程序的输出结果是 。main() int k=0 ; char c='A' ; do switch(c+) case 'A': k+ ; break; case 'B': k-; case 'C': k+=2; break; case 'D': k=k%2 ; contiue ; case 'E': k=k+10 ;

13、break; default: k=k/3 ; k+;while(c<'C') ; printf("k=%dn",k) ; A) k=1 B) k=2 C) k=3 D) k=4 【2.21】下面程序的输出结果是 main() int x,i ;for(i=1 ; i<=100 ;i+) x=i ; if(+x%2=0)if(+x%3=0)if(+x%7=0)printf("%d ",x) ;A) 39 81 B) 42 84 C) 26 68 D) 28 70【2.22】下面程序的输出结果是 _ #include <s

14、tdio.h> main( ) int i,k,a10,p3 ;k=5;for(i=0 ; i<10; i+)ai=i ;for(i=0 ; i<3; i+)pi=ai*(i+1) ;for(i=0 ; i<3; i+)k+=pi*2 ;printf("%dn",k) ;A) 20 B) 21 C) 22 D) 232.23】假定从键盘上输入 "3.6,2.4< 回车 >",下面程序的输出#include <math.h>main() float x,y,z ; scanf("%f,%f"

15、;,&x,&y) ; z=x/y ; while(1) if(fabs(z)>1.0) x=y ; y=z; z=x/y ;else break; printf("%fn",y) ;A) 1.500000 B) 1.600000 C) 2.000000 D) 2.400000【2.24】下面程序的输出结果是 。main() int i,j,x=0 ;for(i=0 ; i<2; i+) x+ ;for(j=0 ; j<-3 ; j+) if(j%2)continue;x+;x+;printf("x=%dn",x) ;A)

16、 x=4 B) x=8 C) x=6 D) x=12【2.25】下面程序的输出结果是main() int i,j,k=10 ;for(i=0 ; i<2; i+) k+ ; int k=0 ;for(j=0 ;j<=3 ;j+) if(j%2) continue ;k+; k+;printf("k=%dn",k) ;A) k=4 B) k=8 C) k=14 D) k=18【2.26】下面程序的输出结果是 #include <stdio.h> main( ) int n33, i, j ; for(i=0 ;i<3;i+ ) for(j=0 ;

17、j<3;j+ ) nij=i+j ; for(i=0 ;i<2;i+ ) for(j=0 ;j<2;j+ ) ni+1j+1+=nij ; printf("%dn", nij) ; A) 14 B) 0 C) 6 D) 不确定【2.27】下面程序的输出结果是 。#include <stdio.h> main( ) int a45=1,2,4,-4,5,-9,3,6,-3,2,7,8,4 ; int i,j,n ;n=9; i=n/5 ; j=n-i*5-1 ; printf("a%d%d=%dn", i,j,aij) ; A

18、) 6 B) -3 C) 2 D) 不确定【2.28】下面程序的输出结果是 。int m33= 1, 2, 3 ;int n33= 1, 2, 3 ; main( ) printf("%dn", m10+n00 ) ; /* */ printf("%dn", m01+n10 ) ; /* */ A) 0 B) 1 C) 2 D) 3 A) 0 B) 1 C) 2 D) 3【2.29】下面程序的输出结果是 。#include <stdio.h> main( ) char s150="some string *",s2=&qu

19、ot;test" printf("%sn", strcat(s1,s2) ;A) some string * B) testC) some stritest D) some string *test【2.30】下面程序的输出结果是 。#include <stdio.h> f(char *s) char *p=s ; while(*p!='0') p+; return(p-s) ; main() printf("%dn",f("ABCDEF") ; A) 3 B) 6 C) 8 D) 0【2.31】

20、下面程序的输出结果是 。#include <stdio.h>#include <string.h> main( ) char str100 ="How do you do" ;strcpy( str + strlen(str)/2, "es she") ; printf("%sn", str) ;A) How do you do B) es she C) How are you D) How does she【2.32】下面程序的输出结果是 。#include <stdio.h> func(int

21、a,int b) int c ; c=a+b; return(c); main() int x=6,y=7,z=8,r ; r=func(x-,y+,x+y),z-) ; printf("%dn",r) ;A) 11 B) 20 C) 21 D) 31【2.33】下面程序的输出结果是 _#include <stdio.h>void fun(int *s) static int j=0 ;do sj+=sj+1 ;while(+j<2) ;main() int k,a10=1,2,3,4,5 ;for(k=1 ;k<3 ; k+)fun(a) ;for

22、(k=0 ;k<5 ; k+) printf("%d",ak) ; A) 35756 B) 23445 C) 35745 D) 12345【2.34】下面程序的输出结果是 _#include <stdio.h> int k=1 ; main( ) int i=4 ; fun(i) ; printf ("n%d ,%d" ,i,k); /* */ fun(int m) m+=k ; k+=m ; char k='B' ;printf("n%d" , k-'A') ; /* */print

23、f("n%d ,%d" ,m,k); /* */ A) 4,1 B) 5,6 C) 4,6 D) A,B,C 参考答案都不对 A) 1 B) -59 C) -64 D) A,B,C 参考答案都不对 A) 5,66 B) 1,66 C) 5,6 D) A,B,C 参考答案都不对【2.35】下面程序的输出结果是 。#include <stdio.h> fun(int n, int *s) int f1, f2 ;if(n=1|n=2)*s=1 ;else fun(n-1, &f1) ;fun(n-2, &f2) ;*s=f1+f2 ;main() i

24、nt x ;fun(6, &x) ; printf("%dn", x) ;A) 6 B) 7 C) 8 D) 9【2.36】下面程序的输出结果是 int w=3 ;main() int w=10 ;printf("%dn",fun(5)*w) ;fun(int k) if(k=0) return(w) ; return(fun(k-1)*k) ;A) 360 B) 3600 C) 1080 D) 1200【2.37】下面程序的输出结果是#include <stdio.h>funa(int a) int b=0 ;static int

25、c=3 ; a=c+,b+ ; return(a);main() int a=2,i,k ;for(i=0 ; i<2; i+) k=funa(a+) ; printf("%dn",k) ;A) 3 B) 0 C) 5 D) 4【2.38】下面程序的输出结果是 。#include <stdio.h> void num() extern int x,y ; int a=15,b=10 ; x=a-b; y=a+b; int x,y ; main() int a=7,b=5 ; x=a-b; y=a+b; num() ; printf("%d,%dn

26、",x,y) ;A) 12,2 B) 5,25 C) 1,12 D) 输出不确定【2.39】下面程序的输出结果是 。main() int a=2,i ;for(i=0 ; i<3; i+) printf("%4d",f(a) ;f(int a) int b=0 ; static int c=3 ; b+; c+; return(a+b+c) ;A) 7 7 7 B) 7 10 13 C) 7 9 11 D) 7 8 9【2.40】下面程序的输出结果是 _ #include <stdio.h> try( ) static int x=3 ; x+;

27、 return(x) ; main( ) int i, x ; for(i=0 ; i<=2 ; i+ )x=try( ) ; printf("%dn", x) ; A) 3 B) 4 C) 5 D) 6【2.41】下面程序的输出结果是#include <stdio.h>main( ) int x=1 ;void f1( ), f2( ) ;f1( );f2(x) ;printf("%dn", x) ;void f1(void) int x=3 ;printf("%d ", x) ;void f2( x )int x

28、 ; printf("%d ", +x) ;A) 1 1 1 B) 2 2 2 C) 3 3 3 D) 3 2 1 【2.42】下面程序的输出结果是 #include <stdio.h> #define SUB(X,Y) (X)*Y main() int a=3,b=4 ; printf("%dn",SUB(a+,b+) ; A) 12 B) 15 C) 16 D) 20【2.43】下面程序的输出结果是 main() int a=1,2,3,4,5,6 ; int *p ; p=a; printf("%d ",*p) ;

29、printf("%d ",*(+p) ; printf("%d ",*+p) ; printf("%d ",*(p-) ; p+=3; printf("%d %d ",*p,*(a+3) ;A) 1 2 3 3 5 4 B) 1 2 3 4 5 6 C) 1 2 2 3 4 5 D) 1 2 3 4 4 5【2.44】下面程序的输出结果是 。main() int a34=1,2,3,4,5,6,7,8,9,10,11,12 ;int *p=a ;p+=6;printf("%d ",*p) ; /

30、* */printf("%d ",*(*(a+6) ; /* */printf("%d ",*(a1+=2) ; /* */ printf("%d",*(&a00+6) ; /* */ A) 7 7 7 7 B) 句语法错误 C) 句语法错误 D) 句语法 错误【2.45】下面程序的输出结果是 。#define FMT "%Xn"#include <stdio.h>main( ) static int a 4 = 1,2,3,4,5,6,7,8,9,10,11,12 ;printf( FMT,

31、a22) ; /* */ printf( FMT, *(*(a+1)+1) ) ; /* */ A) 9 B) 11 C) A D) B A) 6 B) 7 C) 8 D) 前面三个参考答案均是错误的【2.46】下面程序的输出结果是 。#include <stdio.h> main ( ) int a=1, 2, 3, 4, 5 ;int x, y, *p ; p=&a0 ; x=*(p+2) ; y=*(p+4) ; printf("%d,%d,%dn", *p, x, y) ; A) 1,3,5 B) 1,2,3 C) 1,2,4 D) 1,4,5【

32、2.47】下面程序的输出结果是 。void ive(x,n) int x,n ; int t,*p ; p=x+n-1 ; while(x<p) t=*x ; *x+=*p ; *p-=t ; return;main() int i,a=1,2,3,4,5,6,7,8,9,0 ; ive(a,10) ;for(i=0 ; i<10; i+) printf("%d ",ai) ; printf("n") ; A) 1 2 3 4 5 6 7 8 9 0 B) 0 9 8 7 6 5 4 3 2 1C) 1 3 5 7 9 2 4 6 8 0 D

33、) 0 8 6 4 2 9 7 5 3 1【2.48】下面程序的输出结果是#include "string.h" fun(char *w,int n) char t,*s1,*s2 ; s1=w; s2=w+n-1 ; while(s1<s2) t=*s1+ ;*s1=*s2- ;*s2=t ; main() static char *p="1234567" ; fun(p,strlen(p) ; printf("%s",p) ;A) 7654321 B) 1717171 C) 7171717 D) 1711717【2.49】下

34、面程序的输出结果是 #include <stdio.h> char *p = "abcdefghijklmnopq" main( ) int i=0 ;while( *p+!='e' ) ; printf("%cn", *p) ;A) c B) d C) e D) f【2.50】下面程序的输出结果是 。#include <stdio.h> f(int x, int y) return (y-x) ; main( ) int a=5, b=6, c ; int f(), (*g)()=f ; printf("

35、;%dn", (*g)(a,b) ) ;A) 1 B) 2 C) 3 D) 前面三个参考答案均是错误的【2.51】下面程序的输出结果是 。#include <stdio.h> main( ) int a=1,*p,*pp ; pp=&p ; p=&a;a+; printf ("%d,%d,%dn", a,*p, *pp) ;A) 2,1,1 B) 2,1,2 C) 2,2,2 D) 程序有错误【2.52】下面程序的输出结果是 。charmain() *alpha7="ABCD","EFGH",&q

36、uot;IJKL","MNOP","QRST","UVW X","YZ" ; char *p ;int i ;p=alpha; for(i=0 ; i<4; i+) printf("%c",*(pi) ; printf("n") ;A) AEIM B) BFJN C) ABCD D) DHLP【2.53】下面程序的输出结果是 。#include <stdio.h>char *pp23= "abc", "defgh&qu

37、ot;, "ijkl", "mnopqr", "stuvw", "xyz" ;main ( ) printf("%cn",*(pp+1) ; /* */ printf("%cn",*pp0) ; /* */ printf("%cn",(*(*(pp+1)+1)4) ; /* */ printf("%cn",*(pp12+2) ; /* */ printf("%sn",*(pp+1) ; /* */ A) a B) d

38、 C) i D) m A) a B) d C) i D) m A) h B) l C) q D) w A) k B) o C) u D) z A) ijkl B) mnopqr C) stuvw D) xyz【2.54】下面程序的输出结果是 。#include "stdio.h"struct str1 char c5 ;char *s ; main( ) struct str1 s12= "ABCD""EFGH","IJK" ,"LMN" ;struct str2 struct str1 sr

39、;int d ;s2="OPQ" , "RST" ,32767 ;struct str1 *p2 ;p0=&s10 ;p1=&s11 ;printf("%s" , +p1->s) ; /* */printf("%c" ,s2.sr.c2) ; /* */ A) LMN B) MN C) N D) IJK A) O B) P C) Q D) R【2.55】以下程序的输出结果是 。struct st int x,*y ;*p ;int s=10,20,30,40;struct st a=1,&am

40、p;s0,2,&s1,3,&s2,4,&s3; main() p=a ;printf("%dn",+(*(+p)->y) ;A) 10 B) 11 C) 20 D) 21【2.56】以下程序的输出结果是#include <stdio.h>main() union EXAMPLE struct int x,y ;in ;int a,b ;e;e.a=1; e.b=2;e.in.x=e.a*e.b ;e.in.y=e.a+e.b;printf("%d,%dn",e.in.x,e.in.y) ; A) 2,3 B) 4

41、,4 C) 4,8 D) 8,8【2.57】下面程序的输出结果是#include <stdio.h> main() union int i2 ; long k ; char c4 ; r,*s=&r ; s->i0=0x39 ; s->i1=0x38 ; printf("%cn",s->c0) ; A) 39 B) 9 C) 38 D) 8【2.58】下面程序的输出是 。 main ( ) printf("%dn", EOF) ;A) -1 B) 0 C) 1 D) 程序是错误的参考答案【2.1】参考答案: D 注释

42、:程序中除法运算的两个操作数均是整型,运算结果也 是整型。【2.2】参考答案: B注释: C 语言允许在程序块 ( 分程序 )中说明变量。【2.3】参考答案: C注释:变量 i 中的负号传送给变量 n 后,因 n 是无符号数, 已不作为负号处理。【2.4】参考答案: D注释:对变量 x 的 操作是后缀形式,变量 x 的减 1 操作 要在执行完 printf 函数之后才进行,所以变量 x 的值在输出 的时候仍然保持原值 10。【2.5】参考答案: B注释: C 语言在执行 printf() 时,对函数中的表达式表列的处 理顺序是从后向前,即先处理n-,再处理n+,最后处理n, 而且每一个表达式作

43、为一个处理单元,也就是说在不同的表 达式中自增自减运算是单独考虑的。【2.6】参考答案: A注释:变量x和变量y做按位与,结果为 0x0200,右移4位 为 0x0020 ,再与 0x005f 做按位或,最后结果为 0x007f 。【2.7】参考答案: A注释:逗号表达式的结果是用逗号分开的最后一个表达式的 值,此题由于 c='A' 的值是 0,所以逗号表达式的值为 0。 【2.8】参考答案 : B【2.9】参考答案 : A 【2.10】参考答案 : C 注释:在输出格式描述"m.ns"中,m是输出总长度,n是实 际字符的个数, 这里 m 没有给出, 则输出

44、总长度就是实际输 出字符的个数。【2.11】参考答案 : C 【2.12】参考答案: B【2.13】参考答案: C 【2.14】参考答案: B【2.15】参考答案: D 【2.16】参考答案: A【2.17】参考答案 : C 【2.18】参考答案: A【2.19】参考答案 : C注释:在switch语句中,case本身仅起到语句标号的作用, 不会改变语句的流程, 执行 break 语句才能退出当前的 switch 语句。2.20】参考答案 : D注释: siwtch 语句的表达式中,变量 c 是后缀的增一运算, 第一次执行do-while循环时,执行case 'A'后面的语句。

45、【2.21】参考答案 : D 【2.22】参考答案 : B 【2.23】参考答案 : B 注释:fabs()是浮点数绝对值函数。【2.24】参考答案 : A 【2.25】参考答案 : C 注释: C 语言允许在程序块(分程序)内说明变量,如果在 程序块内说明的变量和程序块外的变量同名,在块外说明的 变量在块内是不可见的。可将此题和【 2.11】进行比较,加 深理解。【2.26】参考答案 : C【2.27】参考答案 : B【2.28】参考答案: D A【2.29】参考答案: D【2.30】参考答案 : B 注释:输出结果为字符串长度。【2.31】参考答案 : D注释:字符串拷贝函数strcpy(

46、)要求的两个参数都是字符串首 地址。本题中第二个参数是字符串常量,接受这个字符串的 第一个参量不是直接给出字符数组名,而是进行了地址运算后的结果。由于 str 字符串的长度是 13,除 2 取整后是 6, 第一个参数给出的地址是字符数组 str 的首地址加 6 ,也就是 原来字符串中第二个空格的位置,把"es she"从该处放入,字符串 str 变为 "How does she" 。【2.32】参考答案 : C注释: main 函数调用 func 函数时,第一个实参使用的是逗 号表达式的值,也就是 x+y 的结果。由于对变量 x、y、z 进 行的是后缀运

47、算,所以函数 func 的参数值是 13 和 8。 【2.33】参考答案 : C【2.34】参考答案 : C A C【2.35】参考答案 : C【2.36】参考答案 : B注 释 : 函 数 fun 进 行 了 递 归 调 用 , 实 际 进 行 的 运 算 是 54X32X1X3X100主函数内说明的局部变量w屏蔽了外部变量w,所以在主函数中外部变量w是不可见的,在调用printf 函数时表达式 "fun(5)*w" 中 w 的值是 100【2.37】参考答案 : D注释:main函数三次调用了函数 funa,在funa函数中的静 态变量 c 仅在第一次调用时进行了初始化,再次调用时不再 对静态变量赋初值0【

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论