历年二级C语言笔试真题及答案
A)E,68 B)D,69 C)E,D D)
输出无定值
24)有以下程序
#include <stdio.h>
void fun(int p)
{ int d=2;
p=d++; printf(“%d”,p);}
main()
{ int a=1;
fun(a); printf(“%d\n”,a);} 程序运行后的输出结果是
A)32 B)12 C)21 D)22 25)以下函数findmax拟实现在数组中查找最大值并作为函数值返回,但程序中有错导致不能实现预定功能
#define MIN -2147483647
int findmax (int x[],int n)
{ int i,max;
for(i=0;i<n;i++)
{ max=MIN;
if(max<x[i]) max=x[i];}
return max;
} 造成错误的原因是
A)定义语句int i,max;中max未赋初值B)赋值语句max=MIN;中,不应给max 赋MIN值
C)语句if(max<x[i]) max=x[i];中判断条件设置错D)赋值语句max=MIN;
放错了位置
(26)有以下程序
#include <stdio.h>
main()
{ int m=1,n=2,*p=&m,*q=&n,*r;
r=p;p=q;q=r;
printf(“%d,%d,%d,%d\n”,m,n,*p,*q);
} 程序运行后的输出结果是
A)1,2,1, B)1,2,2,1 C)2,1,2, D)2,1,1,2
27)若有定义语句:int a[4][10],*p,*q[4];且0≤i<4,则错误的赋值是
A)p=a B)q[i]=a[i] C)p=a[i] D)p=&a[2][1]
28)有以下程序
#include <stdio.h>
#include<string.h>
main()
{ char str[ ][20]={“One*World”,
“One*Dream!”},*p=str[1];
printf(“%d,”,strlen(p));printf(“%s\n”,p);
} 程序运行后的输出结果是
A)9,One*World B)9,One*Dream C)
10,One*Dream D)10,One*World
29)有以下程序
#include <stdio.h>
main()
{ int a[ ]={2,3,5,4},i;
for(i=0;i<4;i++)
switch(i%2)
{ case 0:switch(a[i]%2)
{case 0:a[i]++;break;
case 1:a[i]--;
}break;
case 1:a[i[=0;
}
for(i=0;i<4;i++) printf(“%d”,a[i]);
printf(“\n”);
}
A)3 3 4 4 B)2 0 5 0 C)3 0 4 0 D)
0 3 0 4
30)有以下程序
#include <stdio.h>
#include<string.h>
main()
{ char a[10]=”abcd”;
print f(“%d,%d\n”,strlen(a),sizeof(a);
} 程序运行后的输出结果是
A)7,4 B)4,10 C)8,8 D)10,10
31)下面是有关C语言字符数组的描述,
其中错误的是
A)不可以用赋值语句给字符数组名赋字
符串B)可以用输入语句把字符串
整体输入给字符数组
C)字符数组中的内容不一定是字符串
D)字符数组只能存放字符串
32)下列函数的功能是
fun(char * a,char * b)
{ while((*b=*a)!=?\0?) {a++,b++;} }
A)将a所指字符串赋给b所指空间B)
使指针b指向a所指字符串C)将a
所指字符串和b所指字符串进行比较
D)检查a和b所指字符串中是否有?\0?
33)设有以下函数
void fun(int n,char * s) {……} 则下面对
函数指针的定义和赋值均是正确的
是
A)void (*pf)(); pf=fun; B)viod *pf();
pf=fun; C)void *pf(); *pf=fun; D)
void (*pf)(int,char);pf=&fun;
(34)有以下程序
#include <stdio.h>
int f(int n);
main()
{ int a=3,s;
s=f(a);s=s+f(a);printf(“%d\n”,s);
}
int f(int n)
{ static int a=1;
n+=a++;
return n;
} 程序运行以后的输出结果
是
A)7 B)8 C)9 D)10
35)有以下程序
#include <stdio.h>
#define f(x) x*x*x
main()
{ int a=3,s,t;
s=f(a+1);t=f((a+1));
printf(“%d,%d\n?,s,t);
} 程序运行后的输出结果
是
A)10,64 B)10,10 C)64,10 D)
64,64
36)下面结构体的定义语句中,错误的是
A)struct ord {int x;int y;int z;}; struct ord a;
B)struct ord {int x;int y;int z;} struct
ord a;
C)struct ord {int x;int y;int z;} a;
D)struct {int x;int y;int z;} a;
37)设有定义:char *c;,以下选项中能够
使字符型指针c正确指向一个字符串
的是
A)char str[ ]=”string”;c=str;B)
scanf(“%s”,c);C)c=getchar();
D)*c=”string”;
38)有以下程序
#include <stdio.h>
#include<string.h>
struct A
{ int a; char b[10]; double c;};
struct A f(struct A t);
main()
{ struct A
a={1001,”ZhangDa”,1098.0};
a=f(a);jprintf(“%d,%s,%6.1f\n”,a.a,a.b,
a.c);
}
struct A f(struct A t)
2