全国计算机等级考试《二级C语言程序设计》试题(网友回忆版)四
二级C语言程序设计
历年真题
共 43 题
1427 次浏览
更新于 2026-09-28
一、选择题
每小题1分,共40分。
1
有以下程序:
#include
main()
{
int a=5,b=1,t;
t=(a<<2)|b;
printf("%d\n",t);
}
程序运行后的输出结果是( )。
#include
main()
{
int a=5,b=1,t;
t=(a<<2)|b;
printf("%d\n",t);
}
程序运行后的输出结果是( )。
- A.21
- B.11
- C.6
- D.1
2
设函数中有整型变量n,为保证其在未赋值的情况下初值为0,应选择的存储类别是( )。
- A.auto
- B.register
- C.static
- D.auto或register
3
若有以下定义:
int x[10],*pt=x;
则对x数组元素的正确引用是( )。
int x[10],*pt=x;
则对x数组元素的正确引用是( )。
- A.*&x[10]
- B.*(x+3)
- C.*(pt+10)
- D.pt+3
4
有以下程序:
#include
sdivuct ord
{
int x,y;
}dt[2]={1,2,3,4};
main()
{
sdivuct ord *p=dt;
printf("%d",++p->x);
printf("%d",++p->y);
}
程序运行后的输出结果是( )。
#include
sdivuct ord
{
int x,y;
}dt[2]={1,2,3,4};
main()
{
sdivuct ord *p=dt;
printf("%d",++p->x);
printf("%d",++p->y);
}
程序运行后的输出结果是( )。
- A.1,2
- B.2,3
- C.3,4
- D.4,1
5
以下函数按每行8个输出数组中的数据:
void fun(int *w,int n)
{
int i;
for(i=0;i
{
______
printf("%d",w[i]);
}
printf("\n");
}
下划线处应填入的语句是( )。
void fun(int *w,int n)
{
int i;
for(i=0;i
{
______
printf("%d",w[i]);
}
printf("\n");
}
下划线处应填入的语句是( )。
- A.if(i/8==0) printf("\n");
- B.if(i/8==0) continue;
- C.if(i%8==0) printf("\n");
- D.if(i%8==0) continue;
6
有以下程序:
#include
int b=2;
int fun(int*k)
{
b=*k+b;
return(b);
}
main()
{
int a[10]={1,2,3,4,5,6,7,8},i;
for(i=2;i<4;i++)
{
b=fun(&a[i])+b;
printf("%d",b);
}
printf("\n");
}
程序运行后的输出结果是( )。
#include
int b=2;
int fun(int*k)
{
b=*k+b;
return(b);
}
main()
{
int a[10]={1,2,3,4,5,6,7,8},i;
for(i=2;i<4;i++)
{
b=fun(&a[i])+b;
printf("%d",b);
}
printf("\n");
}
程序运行后的输出结果是( )。
- A.1012
- B.810
- C.1028
- D.1016
7
有以下程序:
#include
void fun(char*s)
{
while(*s)
{
if(*s%2==0)printf("%c",*s);
s++;
}
}
main()
{
char a[]=("good");
fun(a);
printf("\n");
}
注意:字母a的ASCII码值为97,程序运行后的输出结果是( )。
#include
void fun(char*s)
{
while(*s)
{
if(*s%2==0)printf("%c",*s);
s++;
}
}
main()
{
char a[]=("good");
fun(a);
printf("\n");
}
注意:字母a的ASCII码值为97,程序运行后的输出结果是( )。
- A.d
- B.go
- C.god
- D.good
8
有以下程序:
#include
main()
{
FILE *f;
f=fopen("filea.txt","w");
fprintf(f,"abc");
fclose(f);
}
若文本文件filea.txt中原有内容为:hello,则运行以上程序后,文件filea.txt中的内容为( )。
#include
main()
{
FILE *f;
f=fopen("filea.txt","w");
fprintf(f,"abc");
fclose(f);
}
若文本文件filea.txt中原有内容为:hello,则运行以上程序后,文件filea.txt中的内容为( )。
- A.helloabc
- B.abelo
- C.abc
- D.abchello
9
有以下程序:
#include
int f(int x,int y)
{
return((y-x)*x);
}
main()
{
int a=3,b=4,c=5,d;
d=f(f(a,b),f(a,c));
printf("%d\n",d);
}
程序运行后的输出结果是( )。
#include
int f(int x,int y)
{
return((y-x)*x);
}
main()
{
int a=3,b=4,c=5,d;
d=f(f(a,b),f(a,c));
printf("%d\n",d);
}
程序运行后的输出结果是( )。
- A.10
- B.9
- C.8
- D.7
10
有以下程序:
#include
#define PT 3.5
#define S(x) PT*x*x
main()
{
int a=1,b=2;
printf("%4.1f\n",S(a+b));
}
程序运行后的输出结果是( )。
#include
#define PT 3.5
#define S(x) PT*x*x
main()
{
int a=1,b=2;
printf("%4.1f\n",S(a+b));
}
程序运行后的输出结果是( )。
- A.14.0
- B.31.5
- C.7.5
- D.程序有错无输出结果
11
有以下程序:
#include
main()
{
int a1,a2;
char c1,c2;
scanf("%d%c%d%c",&a1,&c1,&a2,&c2);
printf("%d,%c,%d,%c",a1,c1,a2,c2);
}
若想通过键盘输入,使得a1的值为12,得a2的值为34.得c1的值为a,得c2的值为b,程序输出结果是:12,a,34,b则正确的输入格式是(以下_代表空格,代表回车)( )。
#include
main()
{
int a1,a2;
char c1,c2;
scanf("%d%c%d%c",&a1,&c1,&a2,&c2);
printf("%d,%c,%d,%c",a1,c1,a2,c2);
}
若想通过键盘输入,使得a1的值为12,得a2的值为34.得c1的值为a,得c2的值为b,程序输出结果是:12,a,34,b则正确的输入格式是(以下_代表空格,代表回车)( )。
- A.12a34b
- B.12_a_34_b
- C.12,a,34,b
- D.12_a34_b
12
设有宏定义:#define IsDIV(k,n) ((k%n==1)?1:0)且变量m已正确定义并赋值,则宏调用:IsDIV(m,5)&&IsDIV(m,7)为真时所要表达的是( )。
- A.判断m是否能被5或者7整除
- B.判断m是否能被5和7整除
- C.判断m被5或者7整除是否余1
- D.判断m被5和7整除是否都余1
13
支持子程序调用的数据结构是( )。
- A.栈
- B.树
- C.队列
- D.二叉树
14
将E-R图转换为关系模式时,实体和联系都可以表示为( )。
- A.属性
- B.键
- C.关系
- D.域
15
有以下程序:
#include
void f(int *p,int *q);
main()
{
int m=1,n=2,*r=&m;
f(r,&n);
printf("%d,%d",m,n);
}
void f(int *p,int *q)
{
p=p+1;
*q=*q+1;
}
程序运行后的输出结果是( )。
#include
void f(int *p,int *q);
main()
{
int m=1,n=2,*r=&m;
f(r,&n);
printf("%d,%d",m,n);
}
void f(int *p,int *q)
{
p=p+1;
*q=*q+1;
}
程序运行后的输出结果是( )。
- A.1,3
- B.2,3
- C.1,4
- D.1,2
16
有两个关系R,S如下:

由关系R通过得到关系S,则所使用的运算为( )。

由关系R通过得到关系S,则所使用的运算为( )。
- A.选择
- B.投影
- C.插入
- D.连接
17
设有定义:char s[81];int i=0;,以下不能将一行(不超过80个字符)带有空格的字符串正确读入的语句或语句组是( )。
- A.gets(s);
- B.while((s[i++]=getchar())!='\n');s[i]='\0';
- C.scanf("%s",s);
- D.do{ scanf("%c",&s[i]);} while(s[i++]!='\n');s[i]='\0';
18
若有定义语句:double x,y,*px,*py;执行了px=&x;py=&y;之后,正确的输入语句是( )。
- A.scanf("%f%f",x,y);
- B.scanf("%f%f"&x,&y);
- C.scanf("%1f%1e",px,py);
- D.scanf("%1f%1f",x,y);
19
以下选项中正确的语句组是( )。
- A.char s[]; s="BOOK!";
- B.char*s; s={"BOOK!"};
- C.char s[10]; s="BOOK!";
- D.char*s; s="BOOK!";
20
有以下程序:
#include
void fun(int*a,int*b)
{
int*c;
c=a;
a=b;
b=c;
}
main()
{
int x=3,y=5,*p=&x,*q=&y;
fun(p,q);
printf("%d,%d",*p,*q);
fun(&x,&y);
printf("%d,%d\n",*p,*q);
}
程序运行后的输出结果是( )。
#include
void fun(int*a,int*b)
{
int*c;
c=a;
a=b;
b=c;
}
main()
{
int x=3,y=5,*p=&x,*q=&y;
fun(p,q);
printf("%d,%d",*p,*q);
fun(&x,&y);
printf("%d,%d\n",*p,*q);
}
程序运行后的输出结果是( )。
- A.3,5,5,3
- B.3,5,3,5
- C.5,3,3,5
- D.5,3,5,3
21
以下选项中,能用作数据常量的是( )。
- A.o115
- B.0118
- C.1-5e1.5
- D.115L
22
数据库应用系统中的核心问题是( )。
- A.数据库设计
- B.数据库系统设计
- C.数据库维护
- D.数据库管理员培训
23
某二叉树有5个度为2的结点,则该二叉树中的叶子结点是数是( )。
- A.10
- B.8
- C.6
- D.4
24
以下是if语句的基本形式:
if(表达式)语句
其中“表达式”( )。
if(表达式)语句
其中“表达式”( )。
- A.必须是逻辑表达式
- B.必须是关系表达式
- C.必须是逻辑表达式或关系表达式
- D.可以是任意合法的表达式
25
下列排序方法中,最坏情况下比较次数最少的是( )。
- A.冒泡排序
- B.简单选择排序
- C.直接插入排序
- D.堆排序
26
下面叙述中错误的是( )。
- A.软件测试的目的是发现错误并改正错误
- B.对被调试的程序进行“错误定位”是程序调试的必要步骤
- C.程序调试通常也称为Debug
- D.软件测试应严格执行测试计划,排除测试的随意性
27
下列叙述正确的是( )。
- A.栈是“先进先出”的线性表
- B.队列是“先进后出”的线性表
- C.循环队列是非线性结构
- D.有序线性表既可以采用顺序存储结构,也可以采用链式存储结构
28
以下程序段中的变量已正确定义
for( i=0; i<4; i++,i++ )
for( k=1; k<3; k++ );
printf("*" );
该程序段的输出结果是( )。
for( i=0; i<4; i++,i++ )
for( k=1; k<3; k++ );
printf("*" );
该程序段的输出结果是( )。
- A.******
- B.****
- C.**
- D.*
29
有以下程序:
#include
main()
{
int x;
scanf("%d",&x);
if(x<=3);
else if(x!=10)
printf("%d\n",x);
}
程序运行时,输入的值在哪个范围内才会有输出结果?( )
#include
main()
{
int x;
scanf("%d",&x);
if(x<=3);
else if(x!=10)
printf("%d\n",x);
}
程序运行时,输入的值在哪个范围内才会有输出结果?( )
- A.不等于10的整数
- B.大于3且不等10的整数
- C.大于3或等于10的整数
- D.小于3的整数
30
若函数中有定义语句:
int k;
则( )。
int k;
则( )。
- A.系统将自动给k赋初值0
- B.这时k中的值无定义
- C.系统将自动给k赋初值-1
- D.这时k中无任何值
31
设变量已正确定义,以下不能统计出一行中输入字符个数(不包含回车符)的程序段是( )。
- A.n=0;while((ch=getchar())!="\n")n++;
- B.n=0;while(getchar()!="\n";n++);
- C.for(n=0;getchar()!="\n";n++);
- D.n=0;for(ch=getchar()!="\n";n++);
32
软件按功能可以分为:应用软件、系统软件、支撑软件(或工具软件)。下面属于应用软件的是( )。
- A.编译程序
- B.操作系统
- C.教务管理系统
- D.汇编程序
33
有以下程序:
#include
main()
{
int a=1,b=2,c=3,d=0;
if(a==1&&b++==2)
if(b!=2||c--!=3)
printf("%d,%d,%d\n",a,b,c);
else printf("%d,%d,%d\n",a,b,c);
else printf("%d,%d,%d\n",a,b,c);
}
程序运行后的输出结果是( )。
#include
main()
{
int a=1,b=2,c=3,d=0;
if(a==1&&b++==2)
if(b!=2||c--!=3)
printf("%d,%d,%d\n",a,b,c);
else printf("%d,%d,%d\n",a,b,c);
else printf("%d,%d,%d\n",a,b,c);
}
程序运行后的输出结果是( )。
- A.1,2,3
- B.1,3,2
- C.1,3,3
- D.3,2,1
34
有以下程序:
#include
main()
{
char *s={"ABC"};
do
{
printf("%d",*s%10);
}while(*s++);
}
注意:字母A的ASCII码值为65,程序运行后的结果是( )。
#include
main()
{
char *s={"ABC"};
do
{
printf("%d",*s%10);
}while(*s++);
}
注意:字母A的ASCII码值为65,程序运行后的结果是( )。
- A.5670
- B.656667
- C.567
- D.ABC
35
以下选项中合法的标识符是( )。
- A.1_1
- B.1-1
- C._11
- D.1_ _
36
有以下程序:
#include
main()
{
char *a[]={"abcd","ef","gh","ijk"};
int i;
for(i=0;i<4;i++)printf("%c",*a[i]);
}
程序运行后的输出结果是( )。
#include
main()
{
char *a[]={"abcd","ef","gh","ijk"};
int i;
for(i=0;i<4;i++)printf("%c",*a[i]);
}
程序运行后的输出结果是( )。
- A.aegi
- B.dfhk
- C.abcd
- D.abcdefghijk
37
耦合性和内聚性是对模块独立性度量的两个标准。下列叙述中正确的是( )。
- A.提高耦合性降低内聚性有利于提高模块的独立性
- B.降低耦合性提高内聚性有利于提高模块的独立性
- C.耦合性是指一个模块内部各个元素间彼此结合的紧密程度
- D.内聚性是指模块间互相连接的紧密程度
38
程序段:
int x=12;
double y=3.141593;
printf("%d%8.6f",x,y);
输出结果是( )。
int x=12;
double y=3.141593;
printf("%d%8.6f",x,y);
输出结果是( )。
- A.123.141593
- B.123.141493
- C.12,3.141593
- D.123.1415930
39
设有定义:
int x=2;
以上表达式中,值不为6的是( )。
int x=2;
以上表达式中,值不为6的是( )。
- A.x*=x+1
- B.x++,2*x
- C.x*=(1+x)
- D.2*x,x+=2
40
有以下程序:
#include
int fun(int x,int y)
{
if(x==y)return(x);
else return((x+y)/2);
}
main()
{
int a=4,b=5,c=6;
printf("%d\n",fun(2*a,fun(b,c)));
}
程序运行后的输出结果是( )。
#include
int fun(int x,int y)
{
if(x==y)return(x);
else return((x+y)/2);
}
main()
{
int a=4,b=5,c=6;
printf("%d\n",fun(2*a,fun(b,c)));
}
程序运行后的输出结果是( )。
- A.3
- B.6
- C.8
- D.12
二、程序填空题
共18分。
41
请补充fun函数,该函数的功能是:按‘0’到‘9’统计一个字符串中的奇数数字字符各自出现的次数,结果保存在数组num中。注意:不能使用字符串库函数。
例如,输入“x=1123.456+0.909*bc”,结果为:1=2,3=1,5=1,7=0,9=2。注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
/**********code.c**********/
#include
#include
#define N 20
fun(char *tt,int num[])
{
int i,j;
int bb[10];
char *p=tt;
for(i=0;i<10;i++)
{
num[i]=0;
bb[i]=0;
}
/**********found**********/
while(①______)
{
if(*p>='0'&&*p<='9')
/**********found**********/
②______;
p++;
}
for(i=1,j=0;i<10;i=i+2,j++)
/**********found**********/
③______;
}
main()
{
char sdiv[N];
int num[10],k;
printf("\nPlease enter a sdiving:");
gets(sdiv);
printf("\n******** The original sdiving ********\n");
puts(sdiv);
fun(sdiv,num);
printf("\n******** The number of letter ********\n");
for(k=0;k<5;k++)
{
printf("\n");
printf("%d=%d",2*k+1,num[k]);
}
printf("\n");
return;
}
/**********-code.c**********/
例如,输入“x=1123.456+0.909*bc”,结果为:1=2,3=1,5=1,7=0,9=2。注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
/**********code.c**********/
#include
#include
#define N 20
fun(char *tt,int num[])
{
int i,j;
int bb[10];
char *p=tt;
for(i=0;i<10;i++)
{
num[i]=0;
bb[i]=0;
}
/**********found**********/
while(①______)
{
if(*p>='0'&&*p<='9')
/**********found**********/
②______;
p++;
}
for(i=1,j=0;i<10;i=i+2,j++)
/**********found**********/
③______;
}
main()
{
char sdiv[N];
int num[10],k;
printf("\nPlease enter a sdiving:");
gets(sdiv);
printf("\n******** The original sdiving ********\n");
puts(sdiv);
fun(sdiv,num);
printf("\n******** The number of letter ********\n");
for(k=0;k<5;k++)
{
printf("\n");
printf("%d=%d",2*k+1,num[k]);
}
printf("\n");
return;
}
/**********-code.c**********/
三、程序改错题
共18分。
42
下列给定程序中,函数fun()的功能是:用选择法对数组中的n个元素按从小到大的顺序进行排序。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
/**********code.c**********/
#include
#define N 20
void fun(int a[],int n)
{
int i,j,t,p;
for(j=0;j {
/********found********/
p=j
for(i=j;i if(a[i]/********found********/
p=j;
t=a[p];
a[p]=a[j];
a[j]=t;
}
}
main()
{
int a[N]={9,6,8,3,-1},i,m=5;
printf("排序前的数据:");
for(i=0;i printf("%d",a[i]);
printf("\n");
fun(a,m);
printf("排序后的数据:");
for(i=0;i printf("%d",a[i]);
printf("\n");
}
/**********-code.c**********/
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
/**********code.c**********/
#include
#define N 20
void fun(int a[],int n)
{
int i,j,t,p;
for(j=0;j
/********found********/
p=j
for(i=j;i
p=j;
t=a[p];
a[p]=a[j];
a[j]=t;
}
}
main()
{
int a[N]={9,6,8,3,-1},i,m=5;
printf("排序前的数据:");
for(i=0;i
printf("\n");
fun(a,m);
printf("排序后的数据:");
for(i=0;i
printf("\n");
}
/**********-code.c**********/
四、程序设计题
共24分。
43
学生的记录由学号和成绩组成,N名学生的数据已在主函数中敲入结构体数组s中,请编写函数fun,它的功能是:按分数的高低排列学生的记录,高分在前。
注意:部分源程序给出如下。请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
/**********code.c**********/
#include
#define N 16
typedef sdivuct
{
char num[10];
int s;
}STREC;
void fun( STREC a[] )
{
STREC tmp;
int i,j;
for(i = 1; i < N; i++)
for(j = 0; j < N-1; j++)
{
/* 请按题目要求,完成一下代码*/
}
}
void main()
{
STREC s[N] = {{"GA005",85}, {"GA003",76}, {"GA002",69}, {"GA004",85}, {"GA001",91}, {"GA007",72}, {"GA008",64}, {"GA006",87},
{"GA015",85}, {"GA013",91}, {"GA012",64}, {"GA014",91}, {"GA011",66}, {"GA017",64}, {"GA018",64}, {"GA016",72}};
int i;
FILE *out ;
fun(s);
printf("The data after sorted :\n");
for(i=0;i {
if((i)%4==0 )printf("\n");
printf("%s %4d ",s[i].num,s[i].s);
}
printf("\n");
out = fopen("out.dat","w");
for(i=0;i {
if( (i)%4==0 && i) fprintf(out, "\n");
fprintf(out, "%4d ",s[i].s);
}
fprintf(out,"\n");
fclose(out) ;
}
注意:部分源程序给出如下。请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
/**********code.c**********/
#include
#define N 16
typedef sdivuct
{
char num[10];
int s;
}STREC;
void fun( STREC a[] )
{
STREC tmp;
int i,j;
for(i = 1; i < N; i++)
for(j = 0; j < N-1; j++)
{
/* 请按题目要求,完成一下代码*/
}
}
void main()
{
STREC s[N] = {{"GA005",85}, {"GA003",76}, {"GA002",69}, {"GA004",85}, {"GA001",91}, {"GA007",72}, {"GA008",64}, {"GA006",87},
{"GA015",85}, {"GA013",91}, {"GA012",64}, {"GA014",91}, {"GA011",66}, {"GA017",64}, {"GA018",64}, {"GA016",72}};
int i;
FILE *out ;
fun(s);
printf("The data after sorted :\n");
for(i=0;i
if((i)%4==0 )printf("\n");
printf("%s %4d ",s[i].num,s[i].s);
}
printf("\n");
out = fopen("out.dat","w");
for(i=0;i
if( (i)%4==0 && i) fprintf(out, "\n");
fprintf(out, "%4d ",s[i].s);
}
fprintf(out,"\n");
fclose(out) ;
}
输入阅读码
查看答案与解析需要输入阅读码