int f(void)
{ static int i = 0; int s =1;
s += i; i++;
return (s);
}
void main(void) {
int i, a = 0;
for (i=0; i<5; i++) a += f() printf(“%d\\n”, a);
}
A) 1 B) 0 C) 非0的数 D) -1
4、执行以下程序段后的输出结果是( )。 int x = 2, y = 3, z; z = (x++, y++); printf(“%d”, z);
A) 3 B) 2 C) 5 D) 4
5、执行以下程序后的输出结果是( )。 #include
int i = 010, j =10, a = 0x10; printf(“%d, %d, %d\\n”, i, j, a);
}
A) 8, 10, 16 B) 8, 10, 10 C) 10, 10, 10 D) 10, 10, 16
6、以下程序的输出结果是( )。 #include
int a = 7, float x = 2.5; y = 4.7;
printf(“%g”, x+a%3*(int)(x+y)%2/4);
}
A) 0 B) 2.75 C) 2 D) 2.5
7、下列语句行中,哪些语句能正确进行字符小、串赋值操作( )。
A) char st[4][5] B) char s[5]={‘A’, ‘B’, ‘C’, ‘D’, ’E’} C) char *s; s = “ABCDE”; D) char *s; scanf(“%s”, s);
8、以下程序的输出结果是( )。 #include
char a[] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, *p = a+5; printf(“%d”, *--p);
}
A) 非法 B) a[4]的地址 C) 3 D) 5
9、以下程序的运行结果是( )。 #include
int a[4][3]={ 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12}; int *p[4], j;
for (j=0; j<4; j++) p[j]=a[j];
printf(\}
A) 4, 4, 9, 8 B) 程序出错 C) 4, 2,12,11 D) 1, 1, 7, 5
10、以下C语言中,对函数不正确的描述是( )。
A) 当用数组名作形参时,形参数组改变可使实参数组随之改变 B) 允许函数递归调用
C) 函数形参的作用范围只是局限于所定义的函数内 D) 函数说明必须在主调函数之前
11、以下所列的各函数首部中,正确的是( )。
A) void play(var :Integer,var b:Integer) B) void play(int a,b)
C) void play(int a,int b) D) Sub play(a as integer,b as integer)
12、以下程序执行后sum的值是( )
void main(void) {
int i , sum;
for (i=1;i<6;i++) sum+=i; printf(\}
A)15 B)14 C) 不确定 D)0
13、以下叙述中不正确的是( )。
A) 在C中,函数中的自动变量可以赋初值,每调用一次,赋一次初值。 B) 在C中,在调用函数时,实在参数和对应形参在类型上只需赋值兼容。 C) 在C中,外部变量的隐含类别是自动存储类别。 D) 在C中,函数形参可以说明为register变量。
41、在C语言中,合法的字符常量是( )。
A) '\\084' B) '\\x43' C) 'ab' D) \
15、以下函数调用语句中含有的实参个数是( )。
func((exp1,exp2),(exp3,exp4,exp5));
A) 1 B) 2 C) 4 D) 5
二、程序填空(26分)
1、定义compare(char *s1, char *s2)函数,以实现比较两个字符串大小的功能。 #include
void compare(char *s1, char *s2) {
while(*s1&&*s2&& ) {
s1++;
; }
return ; }
void main(void) {
printf(\}
2、函数fun的功能是:使字符串str按逆序存放。 void fun (char str[]) {
char m; int i, j;
for (i=0, j=strlen(str); i< ; i++, j--) { m = str[i];
str[i] = ; str[j-1] = m; }
printf(\}
3、以下程序的功能是:从键盘上输入若干个学生的成绩,统计计算出平均成绩,并输出低于平均分的学生成绩,用输入负数结束输入。请填空。 #include
float x[1000],sum=0.0,ave,a; int n=0,i;
printf(\:\\n\; scanf(\,&a);
while (a>=0.0&& n<1000) {
sum+ ; x[n]= ; n++; scanf(\,&a); }
ave= ; printf(\:\\n\; printf(\,ave); for (i=0;i if ( ) printf (\} 4、以下fun函数的功能是:累加数组元素中的值.n为数组中元素的个数, 累加的和值放入x所指的 存储单元中。 void fun(int b[ ],int n, int *x) { int k, r=0; for (k=0; k } 7、 阅读程序,8、 写出程序的输出结果(24分) 1、#include int x = 1; { int x = 2; { int x = 3; printf(“x= %d\\n”, x); } printf(“x= %d\\n”, x); } printf(“x= %d\\n”, x); } 2、#include static char s[] = “china”, c; int i, j; for (i=0; i<5; i++) for (j=4; j>=1; j--) if (s[j] c = s[j]; s[j] = s[j-1]; s[j-1] = c; } printf(“%d\\n”, *(p[0]+1) + **(q+2)); } 3、include static int b=0; a++; b++; printf(\} void main(void) { int i; for (i=1; i<=3; i++) f( i ); } 4、#include struct stu { int num; char name[10]; int age; }; void fun(struct stu *p) { printf(\ } void main(void) { struct stu students[3]={ {9801,\ fun(students+2); } 四、编程(35分) (1)输入一个double 类型的数,使该数保留小数点后2位,且对第3位进行四舍五入处理。 (2)编写函数strcopy(s, t),将字符串 s 复制到字符串 t 中。 (3)求2~1000中的所有完数(某数因子和等于其本身的数称为完数。例:28的因子是1,2,4, 7,14,且1+2+4+7+14=28,故28是完数。) c语言程序设计模拟试题C 专业 班级 学号 姓名 题号 一 得分 二 三 四 五 六 七 八 总分 9、 单选题(15分) 1、若变量a 是int 类型,并执行了语句a = ‘A’+1.6;后,则正确的叙述是( )。 A) a的值是字符’C’ B) a的值是浮点型 C) a的值是字符’A’的ASCII值加1 D) 不允许字符型和浮点型相加 2、执行以下程序段后,变量y的值是( )。 int x, y; x = 1; y = (++x*5); A) 5 B) 10 C) 15 D) 20 3、9、执行以下程序段后的输出结果是( ) int a = 10; printf(“%d ”, ++x); printf(“%d ”, x--) A) 11 10 B) 11 11 C) 10 11 D) 10 10 4、执行以下程序后的输出结果是( ) #include int x = 10; printf(“%d %d %d\\n”,++x, --x, -x++); } A) 11 10 -10 B) 10 10 -10 C) 10 11 -11 D) 11 11 -10 5、下面正确的自定义标识符是( ) A) a2b3 B) int C) int abc D) 2a3b
C语言模拟复习题



