资源描述
2010年3月二级c语言笔试真题及答案
试题:
一、选择题
(11) 以下叙述正确的是
A)C语言程序是由过程和函数组成的
B)C语言函数可以嵌套调用,例如:fun(fun(x))
C)C语言函数不可以单独编译
D)C语言中除了main函数,其他函数不可以作为单独文件形式存在
(12) 以下关于C语言的叙述中正确的是
A)C语言中的注释不可以夹在变量名或关键字的中间
B)C语言中的变量可以再使用之前的任何位置进行定义
C)在C语言算术的书写中,运算符两侧的运算数类型必须一致
D)C的数值常量中夹带空格不影响常量值的正确表示
(15)
#include <stdio.h>
void main()
{
char a,b,c,d;
scanf(”%c%c”,&a,&b);
c=getchar(); d=getchar();
printf(”%c%c%c%c\n”,a,b,c,d);
}
当执行程序时,按下列方式输入数据(从第一列开始,<CR>代表回车,注意:回车是一个字符)
12<CR>
34<CR>
则输出结果是:
A、1234 B、12 C、12 D、12
3 34
16、以下关于C语言数据类型使用的叙述中错误的是:
A、若要准确无误的表示自然数,应使用整数类型。
B、若要保存带有多位小数的数据,应使用双精度类型。
C、若要处理如”人员信息”等含有不同类型的相关数据,应自定义结构体类型。
D、若只处理”真”和”假”两种逻辑值,应使用逻辑类型。
(24)以下关于return语句的叙述中正确的是
A)一个自定义函数中必须有一条return语句
B) 一个自定义函数中可以根据不同情况设置多条return语句
C)定义成viod类型的函数中可以有带返回值的return语句
D)没有return语句的自定义函数在执行结束时不能返回到调用处
(25)下列选项中,能够正确定义数组的语句是
A)int num[0..2008]; B) int num[];
C) int N=2008; D) #define N 2008
int num[N]; int num[N]
(26)有以下程序
#include<stdio.h>
void fun (char*c,int d)
{*c=*c+1;d=d+1;
printf(”%c,%c,”,*c,d);}
main()
{char b=’a’,a=’A’;
fun(&b,a); printf(”%c,%c\n”,b,a);}
程序运行后的输出结果是
A)b,B,b,A B)b,B,B,A C)a,B,B,a D)a,B,a,B
(27)若有定义int(*pt)[3];,则下列说法正确的是
A)定义了基类型为int的三个指针变量
B)定义了基类型为int的具有三个元素的指针数组pt。
C)定义了一个名为*pt、具有三个元素的整型数组
D)定义了一个名为pt的指针变量,它可以指向每行有三个整数元素的二维数组
(28)设有定义double a[10],*s=a;,以下能够代表数组元素a[3]的是
A)(*s)[3] B)*(s+3) C)*s[3] D)*s+3
(29)有以下程序
#include<stdio.h>
main()
{ int a[5]={1,2,3,4,5}, b[5]={0,2,1,3,0},s=0
for(i=0;i<5;i++) s=s+a[b[i]];
printf("%d\n",s);}
程序运行后的输出结果是
A) 6 B) 10 C) 11 D)15
30)有以下程序,程序运行后的输出结果是
#include<stdio.h>
main()
{ int b[3] [3]={0,1,2,0,1,2,0,1,2},i,j,t=1;
for(i=0; i<3; i++)
for(j=i;j<=i;j++) t+=b[i][b[j][i]];
Printf("%d\n",t);}
A)1 B)3 C)4 D)9
(31)若有以下定义和语句,则输出结果是
char sl[10]= "abcd!", *s2="n123\\";
printf("%d %d\n", strlen(s1),strlen(s2));
A) 5 5 B)10 5 C)10 7 D)5 8
(32)有以下程序,程序运行后的输出结果是
#include<stdio.h>
#define N 8
void fun(int *x,int i)
{*x=*(x+i);}
main()
{ int a[N]={1,2,3,4,5,6,7,8},i;
fun(a,2);
for(i=0; i<N/2); i++)
{ printf("%d",a[i]);}
printf("\n");}
A)1 3 1 3 B) 2 2 3 4 C) 3 2 3 4 D)1 2 3 4
(33)有以下程序
#include<studio.h>
int f(int t [ ],int n);
main()
{int a[4]={1,2,3,4},s;
s=f{a,4}; printf(”%d\n”,s);}
int f(int t[], int n)
{ if (n>0) return t[n-1]+f(t,n-1);
else return 0;}
程序运行后的输出结果是
A)4 B)10 C)14 D)6
(34)有以下程序
#include<studio.h>
int fun()
{static int x=1;
x*=2; return x;}
main()
{int I,s=1;
for (i=1;i<=2;i++) s=fun();
printf(”%d\n”,s);}
程序运行后的输出结果是
A)0 B)1 C) 4 D)8
(35)以下程序
#include <stdio.h>
#define SUB(a) (a)-(a)
main()
{int a=2,b=3,c=5,d;
d=SUB(a+b)*c;
printf(”%d\n”,d);}
程序运行后的结果是
A)0 B)-12 C)-20 D)10
(36)没有定义
struct complex
{ int real, unreal ;} datal={1,8},data2;
则以下赋值语句中的错误的是
A)data2=data1; B)data2=(2,6);
C)data2.real1=data1.real; D)data2.real=data1.unreal;
(37)有以下程序,程序运行后的输出结果是
#include <studio.h>
#include <string.h>
struct A
{int a; char b[10];double c;};
void f(struct A t);
main()
{struct A a={1001,”ZhangDa”,1098.0};
f(a); pringt(”%d,%s,%6.1f\n”,a.a,a.b,a.c);}
void f(struct A t)
{t.a=1002;strcpy(t.b,”ChangRong”);t.c=1202.0;}
A)1001,ZhangDa,1098.0 B)1002,ChangRong,1202.0
C)1001,ChangRong,1098.0 D)1002,ZhangDa,1202.0
(38)有以下定义和语句
struct workers
{int num; char name[20];char c;
srruct
{int day;int month;intyear;} s;};
struct workers w,*pw;
pw=&w
能给w中year成员赋1980的语句是
A)*pw.year=1980; B)w.year=1980;
C)pw->year=1980; D)w.s.year=1980;
(39)有以下程序
#include <stdio.h>
main()
{int a=2,b=2,c=2;
printf(”%d\n”,a/b&c);}
程序运行后的结果是
A)0 B)1 C)2 D)3
(40)以下程序,程序运行后的输出结果是
#include<stdio.h>
main( )
{ FILE *fp;char str[10];
fp=fopen(”myfile.dat”,”w”);
fputs(”abc”,fp); fclose(fp);
fp=fopen(”myfile.dat”,”a+”);
rewind(fp,”gd”,28);
rewind(fp);
fscanf(fp,”gs”,str); puts(str);
fclose(fp); }
A)abc B)28c C)abc28 D)因类型不一致而出错
二、填空题(每空2分,共30分)
(6)设x为int型变量,请写出一个关系表达式 :x%3==0&&x%7==0 ,用以判断x同时为3和7的倍数时,关系表达式的值为真。
(7)有以下程序
#include < stdio.h >
main()
{ int a=1,b=2,c=3,d=0;
if (a==1)
if (b!=2)
if(c!=3) d=1;
else d=2;
else if(c!=3) d=3;
else d=4;
else d=5;
printf(”%d\n”,d);}
程序运行后的输出结果是: _________。
(8)有以下程序,程序运行后,当输入14 63<回车>时,输出结果是_______
#include < stdio.h >
main()
{ int m,n;
scanf(”%d%d”,&m,&n);
while (m!=n)
{ while(m>n) m=m-n;
while(m<n)n=n-m;}
printf(”%d\n”,m);}
(9)有以下程序
#include <stdio.h>
main ()
{ int I,j,a[][3]={1,2,3,4,5,6,7,8,9};
for (i=1;i<3;i++)
for(j=I;j<3;j++) printtf(”%d”,a[i][j]);
printf(”\n”);
}
程序运行后的输出结果是 123569
(10) 有以下程序
#include <stdio.h>
main()
{ int []={1,2,3,4,5,6},*k[3],i=0;
while(i<3)
{ k[i]=&a[2*i];
printf(”%d”,*k[i]);
i++; }}
程序运行后的输出结果是______
(11) 有以下程序
#include <stdio.h>
main()
{ int a[3][3]={{1,2,3},{4,5,6},{7,8,9}};
int b[3]={0},i;
for(i=0;i<3;i++) b[i]=a[i][2]+a[2][i];
for(i=0;i<3;i++) printf(”%d”,b[i]);
printf(”\n”);}
程序运行后的结果是_________
(12) 有以下程序
#include <stdio.h>
#include <string.h>
void fun(char*str)
{ char temp; int n,i;
n=strlen(str);
temp=str[n-1];
for(i=n-1;i>0;i--) str[i]=str[i-1];
str[0]=temp;}
main()
{ char s[50];
scanf(”%s”,s); fun(s); printf(”%s\n”,s);}
程序运行后输入:abcdef<回车>,则输出结果是____________
13、以下程序的功能是:将值为三位正整数的变量x中的数值按照个位、十位、百位的顺序拆分并输出。请填空。
#include<stdio.h>
main()
{ int x=256;
printf(”%d-%d-%d\n”, X%10 ,x/10%10,x/100);}
14、以下程序用以删除字符串中的所有空格请填空。
#include<stdio.h>
main()
{ char s[100]={”our .tercher teach c language!”};
int i,j;
for( i=j=0;s[i]!=‘\0’;i++)
if(s[i]!=‘\0’ ’) { s[j]=s[i];j++; }
s[j]=______;
printf(”%s\n”,s);}
(15)以下程序功能是:借助指针变量找出数组元素中的最大值及其元素的下标值。请填空。
#include <stdio.h>
main()
{ int a[10],*p,*s;
for(p=a;p-a<10;p++) scanf(”%d”,p);
for(p=a,s=a;p-a<10;p++) if(*p>*s) s=__________;
printf(”index=%d\n”,s-a);
展开阅读全文