课程代码: 21042 适用专业: 计算机应用、应用电子
一、判断题 (每小题1分,共5分) 1.内部静态变量有隐含初值。( ) 2.break语句只能用于for循环。( ) 3.C语言不支持动态数组。( ) 4.(n+1)++是一个正确的表达式。( ) 5.在C中函数可以返回任何类型。( )
二、简答题 (共45分) 1.简述C语言中break,continue,goto和return语句的作用。(10分) 2.计算下列表达式。(10分) int a,b,c,x; a=2;b=3;c=7;d=19; x=d/b%a; x_________ x=d%c+b/a*5+5; x_________ int a,b,c /*下面语句连续执行*/ a=b=c=0; a=++b+c++; a____ b____ c____ a=b--+--c; a____ b____ c____ int a,b,c,d; a=2;b=-3;c=7;d=-19; x______ x=a&&b||c; x=a||b&&c||d+19; x______ 3.用一个while循环改写下面程序段,要求改写后两者功能完全一样。(5分) for(i=0;c!=''&&c!='\t'&&c!='\n'&&c!=EOF;i++){ word[i]=c; c=getchar(); } 4.用宏定义写出求二个数最小值的函数MIN(a,b)。(5分) 5.(1)写出下面说明中变量的含义。(6分) char *a, *b[], (*c)[], *(*d)[], (*e)(); (2)A是一个函数,其返回值为指向整型数组的指针,写出A的说明。(5分) (3)用类型定义typedef写出A的定义。(5分)
三、程序分析题 (每小题10分,共30分) 1.改正下面程序中可能的语法错误(可直接在原语句旁改正)。 main( ) { char c; char array[],*pos; array="ABCDEFGHIJKLMNOPRSTUVWXYZ" scanf("%c%s",c,pos); pos=find(array,c) } /*finding char c in string s */ { char * low=s; char * high=s+strlen(s)=1; char * mid while(low<=high){ mid=(high+low)/2 if(mid==c) return mid; else if (mid int i=1; main() { int i,j; i=reset(); printf("%d",i); for(j=1;j<=3;j++){ printf("%d",next(i)); printf("%d",last(i)); printf("%d",new(i+j)); } } int reset(void) { return(i); } int next(int j) { return(j=i++); } int last(int j) { static int i=10; return(j=i--); } int new(int i) { return(i=10+i); } 3.在下面程序中的_________处填上适当的部分,使其能完成正确的功能。(每空2分,共10分) [程序说明] 该程序功能是统计标准输入中数字字符、空白字符和其它字符的数目。 #include main() /* count digits, white spaces, others */ { int c,i,nwhite,nother,ndigit[10]; nwhite=nother=0; for(i=0;i<____;i++) ndigit[i]=0; while((c=getchar())!=EOF){ switch(c){ case '0':case '1':case '2':case '3':case '4': case '5':case '6':case '7':case '8':case '9': ndigit[c-___]++; break; case ' ': case '\n': case '\t': nwhite++; ______; default: ______; break; } } printf("digits="); for(i=0;i<10;i++) printf("%d",_______); printf(",white space=%d,other=%d\n",nwhite,nother); }
四、程序设计题(共20分) 写一程序将一个文件拷贝至另一个文件,其中在所拷贝的文件中,制表符('\t')用8个空格代替,该程序的文件名由命令行参数输入。 例如: C>fcopy file1 file2 其中fcopy为该程序的执行文件名,file1为源文件名,file2为目标文件名。
|