资源描述
《C次第 方案 》期末复习练习 题及参考答案 (3)
一、单项选择 题
1.假设 有定义 int (*p)[4],那么标识符p是一个 。
A〕指向整型变量的指针变量
B〕指向函数的指针变量
√C〕指向有四个整型元素的一维数组的指针变量
D〕指针数组名,有四个元素,每个元素均为一个指向整型变量的指针
2.以下对字符串的定义 中,差错 的选项是: 。
√A) char str[7] = "FORTRAN";
B) char str[] = "FORTRAN";
C) char *str = "FORTRAN";
D) char str[] = {'F','O','R','T','R','A','N',0};
3.针对下面次第 段,下面哪些说法是精确 的?
#include <stdio.h>
void Swap(int *x, int *y);
main()
{ int a, b;
a = 5;
b = 9;
Swap(&a, &b);
printf("a=%d,b=%d",a,b);
}
void Swap(int *x, int *y)
{ int *pTemp;
*pTemp = *x;
*x = *y;
*y = *pTemp;
}
A) 次第 运行 结果为乱码;
B) 次第 运行 后将导致 次第 崩溃;
C) 次第 编译时出错 导致 次第 无法 运行 ;
√ D) 次第 实行 了危险 的把持 ;
4.已经清楚 老师 记录 描画为:
struct student
{ int no;
char name[20];
char sex;
struct
{ int year;
char month[15];
int day;
}birth;
};
struct student s;
设变量s中的生日 是1984年11月11日,以下对生日 的精确 赋值办法 是_____
√
5. 要使下面次第 的输出1, 2, 34,那么从键盘输出的数据格式 应为 。
#include <stdio.h>
main()
{ char a,b;
int c;
scanf("%c%c%d",&a,&b,&c);
printf("%c,%c,%d\n",a,b,c);
}
A〕1 2 34 B〕1, 2, 34 C〕’1’,’2’,34 √ D〕12 34
6. 以下选项中为合理 整型常量的是〔 〕。
A) -080 √B) -80 C) -8e1.0 D) -80.0e
7. 假设 x,i,j跟 k根本上 int型变量,那么打算 表达 式x=(i=4,j=16,k=32)后,x的值为〔 〕。
A) 4 B) 16 √C) 32 D) 52
8. 以下次第 实行 后的输出结果是〔 〕。
#include <stdio.h>
void func(int *a, int b[])
{ b[0]=*a+6; }
main()
{ int a,b[5];
a=0; b[0]=3;
func(&a,b); printf("%d\n",b[0]);
}
√A)6 B)7 C)8 D)9
9. 设有定义 char grade = 'A'; 那么以下给出的次第 运行 结果或说法精确 的选项是〔 〕。
switch(grade)
{ case 'A':
case 'B':
case 'C': printf(">= 60 pass!\n");
case 'D': printf("< 60\n");
default : printf("error!\n");
}
A) >= 60 pass! B) < 60 C) error! √D) 以上结果都不精确
10. 以下次第 实行 后的输出结果是〔 〕。
#include <stdio.h>
int main()
{ int i = 1, j = 1, k = 2;
if((j++ || k++ ) && i++ )
printf("%d,%d,%d\n", i, j, k);
return 0;
}
A) 1,1,2 B) 2,2,1 √C) 2,2,2 D) 2,2,3
11. 实行 完循环 语句 for(i = 1; i < 10; i++); 后,以下关于 变量i的值及循环 体的实行 次数的说法精确 的选项是〔 〕。
A) i的值是9,循环 体实行 9次 B) i的值是9,循环 体实行 10次
√C) i的值是10,循环 体实行 9次 D) i的值是10,循环 体实行 10次
12. 以下次第 的运行 结果是〔 〕。
#include <stdio.h>
int main()
{ int m, n;
for(m = 0, n = 10; m < n; m+=3, n--);
printf("%d,%d\n",m,n);
return 0;
}
A) 6,7 B) 7,6 √C) 9,7 D) 7,9
13. 以下次第 的运行 结果是〔 〕。
#include <stdio.h>
int main()
{ int i;
int a[3][3]={1,2,3,4,5,6,7,8,9};
for(i = 0; i < 3; i++)
printf("%d ",a[2-i][i]);
return 0;
}
A) 1 5 9 √B) 7 5 3 C) 3 5 7 D) 5 9 1
14. 以下可用于C语言 用户标识符的一组是〔 〕。
A)void, define, WORD √B)a3_3,_123,Car
C)For, -abc, IF Case D)2a, DO, sizeof
15. 假设 恳求 在if后一对圆括号中表示 a不等于 0的关系 ,那么能精确 表示 这一关系 的表达 式为〔 〕。.
A) a<>0 B) !a C) a=0 √D) a!=0
16. 以下次第 的输出结果是〔 〕。
#include<stdio.h>
void main()
{ int x=10,y=10;
printf("%d %d\n", x--, --y);
}
A) 9 9 √B) 10 9 C) 9 10 D) 10 10
17. 假设 有定义 :char *name[] = {"Follow me","BASIC","Great Wall","FORTRAN"};,那么name[2]的值是〔 〕。
A) 字符'G' B) 字符串"Great Wall"
√C) 字符串"Great Wall"的首所在 D) 不判定
18. 有以下次第 ,次第 实行 后的输出结果是〔 〕。
#include <stdio.h>
void fun(char *p)
{ char *q = p;
while( *q != '\0')
{ (*q) ++;
q++;
}
}
int main()
{ char a[] = {"Program"}, *p;
p = &a[3];
fun(p);
printf("%s\n",a);
return 0;
}
√A) Prohsbn B) Prphsbn C) Progsbn D) Program
19. 下面列出的C语言 供应 的合理 的数据典范 关键 字是〔 〕。
A) Double √B) short C) integer D) Char
20. 字符(char)型数据在微机内存中的存储办法 是〔 〕。
A) 反码 B) 补码 C) EBCDIC码 √D) ASCII码
21. 设 int a=12,那么实行 完语句a+=a-=a*a后,a的值是〔 〕。
A) 552 B) 264 C) 144 √D) -264
23. 可以 完成 如下函数打算 的次第 段是〔 〕。
-1 x<0
Y= 0 x=0
1 x>0
A) y=1; √B) if (x>=0)
if(x!=0) if(x>0) y=1;
if(x>0) y=1; else y=0;
else y=0; else y=-1;
C) y=0; D) y=-1;
if (x>=0) if (x>0) y=1;
if (x>0) y=1; else y=0;
else y=-1;
24. 有如下次第
#include <stdio.h>
void main( )
{ int x=1,a=0,b=0;
switch(x)
{
case 0: b++;
case 1: a++;
case 2: a++;b++;
}
printf("a=%d,b=%d\n",a,b);
}
该次第 的输出结果是〔 〕。
√A) a=2,b=1 B) a=1,b=1 C) a=1,b=0 D) a=2,b=2
25. 下面次第 的输出结果是〔 〕。
#include<stdio.h>
void main( )
{ int i;
for(i=1;i<6;i++)
{ if (i%2!=0) {printf("#");continue;}
printf("*");
}
printf("\n");
}
√A) #*#*# B) ##### C) ***** D) *#*#*
26. C语言 中while 跟 do-while 循环 的要紧区不是〔 〕。.
√A) do-while的循环 体至少无条件 实行 一次
B) while 的循环 把持 条件 比do-while 的循环 把持 条件 严峻
C) do-while 赞同 从外部转到循环 体内
D) do-while 的循环 体不克不迭 是复合语句
27. 当对两个字符串停顿比较时,该当 应用 的函数是〔 〕。
A〕 strcat √B〕 strcmp C〕 strcpy D〕 strlen
28. 以下次第 的运行 结果是〔 〕。
#include<stdio.h>
void main( )
{ int *p, a=1;
p=&a;
*p=10;
printf("%d\n", a);
}
A) 1 √B) 10 C) 不克不迭 判定 D) 11
29. 设有定义 int a[ ]={1,5,7,9,11,13}, *p=a+3; 那么*(p-2) , *(a+4) 的值是〔 〕。
√A〕5 11 B〕1 9 C〕5 9 D〕有差错
30. 假设 i为整型变量,那么以下循环 的次数是〔 〕。
for(i=2;i==0;)printf(“%d〞,i--);
A〕 无限次 √B〕 0次 C〕 1次 D〕 2次
二、填空题
1. C语言 标识符由 ___字母______、____数字______跟 ______下划线_____来构造。
2. 设有定义 :FILE *fp;,请将以下打开 文件的语句补偿 残缺,以便可以 向文本文件readme.txt的最后续写内容。fp = fopen("readme.txt", “a〞 );
3. 假设 有说明跟 语句:int a=25,b=60;b=++a;那么b的值是 26 。
4. 假设 int x=5;while〔x>0〕printf(“%d〞,x--);的循环 实行 次数为 5 。
5. 假设 有int a[5],*p=a;那么p+2表示 第 三 个元素的所在 。
6. 假设 有说明跟 语句:int a=5,b=6,y=6;b-=a;y=a++那么b跟 y的值分不是 1 、 5 。
7. 已经清楚 整型变量a=3,b=4,c=5,写出逻辑表达 式a||b+c>c&&b-c的值是 1 。
8.在C语言 中,变量的存储类不有四种,它们是:
自动 (auto)、寄存器(register)、静态(static) 、外部 (extern)。
9.假设一个变量在某个范围 内是有效的,该范围 就称为变量的感染 域。自动 (auto)存储类不的局部变量,其感染 域为:从定义 的位置起,到函数体〔或复合语句〕终了为止
10.设有定义 int a,b;写出称心 条件 “a是3的倍数,或者 b不是5的倍数〞的逻辑表达 式: a%3==0 || b%5!=0 。
三、次第 运行 结果分析题
1.
main()
{ int i,j,x =0;
for(i=0;i<2;i++)
{
x++;
for(j=0;j<3;j++)
{
if(j%2) continue;
x++;
}
x++;
}
printf("x=%d\n",x);
}
次第 运行 结果是: x=8
2.
#include <stdio.h>
struct date
{ int year;
int month;
int day;
};
struct date func(struct date p)
{ p.year = 2000;
p.month = 5;
p.day = 22;
return p;
}
main()
{ struct date d;
d.year = 1999;
d.month = 4;
d.day = 23;
printf("%d/%d/%d\n", d.year, d.month, d.day);
d = func(d);
printf("%d/%d/%d\n", d.year, d.month, d.day);
}
次第 的运行 结果是:
1999/4/23
2000/5/22
3.
#include <stdio.h>
main()
{
char a[] = "Hello" ;
char *p = NULL;
for (p=a; p<a+5; p++)
{
printf("%s\n", p);
}
}
次第 运行 结果是:
Hello
ello
llo
lo
o
4.
#include <stdio.h>
int fun(int x, int y)
{return x > y ? x : y;}
main()
{ int a=2,b=5,c=8;
printf("%d\n", fun(fun(a+c,b), a-c));
}
次第 运行 结果是:10
5.
#include <stdio.h>
void Func(void);
main()
{ int i;
for (i=0; i<5; i++)
{ Func(); }
}
void Func(void)
{ static int a = 1;
int b = 2, c;
c = a + b;
a++;
b++;
printf("%d\n", c);
}
次第 运行 结果是:
3
4
5
6
7
6.当运行 以下次第 时,从键盘输出如下内容并回车:ADescriptor ,那么下面次第 的运行 结果是 v0=13,v1=4,v2=12 。
#include <stdio.h>
int main()
{ char c;
int v0 = 1, v1= 0, v2 = 0;
do
{ switch(c = getchar())
{
case 'a':case 'A':
case 'e':case 'E':
case 'i':case 'I':
case 'o':case 'O':
case 'u':case 'U': v1 += 1;
default: v0 += 1; v2 += 1;
}
} while (c != '\n');
printf("v0=%d,v1=%d,v2=%d\n",v0,v1,v2);
printf("\n");
return 0;
}
7. 当运行 以下次第 时,运行 结果是_______。
#include <stdio.h>
void fun(char *t, char *s)
{ while( *t != 0) t++;
while( ( *t ++ = *s ++ ) != 0 ) ;
}
int main()
{ char ss[3][20]={"I ","don’t ","know"};
int i;
for(i = 2; i > 0; i--)
fun(ss[i - 1], ss[i]);
for( i = 0; i < 3; i++)
printf("%s\n",ss[i]);
return 0;
}
I don’t know
don’t know
know
8. 当运行 以下次第 时,运行 结果是___1,5,3,8,____。
#include <stdio.h>
int main()
{ int a[][4] = {{2,9,1,8},{8,9,7,2},{4,3,2,1},{1,5,3,5}}, i, j, k, t;
for(i = 0; i < 4; i++)
{for(j = 0; j < 3; j++)
{for(k = j + 1; k < 4; k++)
if(a[j][i] > a[k][i]){t = a[j][i]; a[j][i] = a[k][i]; a[k][i] = t; }
}
}
for(i = 0; i < 4; i++) printf("%d,",a[i][i] );
return 0;
}
9. 有以下次第
#include <stdio.h>
#include <string.h>
typedef struct{ char name[9]; char sex; float score[2]; }STU;
void f(STU a)
{ STU b={"Zhao",′m′,85.0, 90.0}; int i;
strcpy(a.name,b.name);
a.sex=b.sex;
for(i=0;i<2;i++) a.score[i]=b.score[i];
}
main()
{ STU c={"Qian",′f′,95.0,92.0};
f(c);
printf("%s,%c,%2.0f,%2.0f\n",c.name,c.sex,c.score[0],c.score[1]);
}
次第 的运行 结果是_____ Qian,f,95,92_______。
四、次第 填空题
阅读 次第 ,在标有下划线的空白 处填入适当 的表达 式或语句,使次第 残缺并符合 题目 恳求 。
1. 先按学号由小到大年夜 的次第 从键盘输出老师 的学号跟 效果,然后 从键盘任意 输出一个老师 的学号,查寻 并打印存在 该学号的老师 的效果。
#include <stdio.h>
#define ARR_SIZE 40
int BinSearch(long a[], int n, long x);
main()
{ float score [ARR_SIZE];
int n, i, pos;
long num[ARR_SIZE], x;
printf("Please enter total number:");
scanf("%d", &n);
printf("Please enter the number and score:\n");
for (i=0; i<n; i++)
{
scanf("%ld%f", &num[i], &score[i]);
}
printf("Please enter the searching number:");
scanf("%ld", &x);
pos = BinSearch(num, n, x);
if (pos != -1)
{
printf("score = %4.0f\n", score[pos]);
}
else
{
printf("Not found!\n");
}
}
int BinSearch(long a[], int n, long x)
{
int low, high, mid;
low = 0;
high = n - 1;
while (low <= high)
{
mid = (high + low) / 2;
if (x > a[mid])
{
low = mid + 1;
}
else if (x < a[mid])
{
high = mid - 1;
}
else
{
return (mid);
}
}
return(-1);
}
2. 输出一行字符,统计其中 的英文字 符、数字字符、空格及其他 字符的个数。
#include <stdio.h>
#include <string.h>
#define ARR_SIZE 80
main()
{
char str[ARR_SIZE];
int len, i, letter=0, digit=0, space=0, others=0;
gets(str);
for (i=0; str[i]!='\0'; i++)
{
if (str[i] >= 'a' && str[i] <= 'z' || str[i] >= 'A' && str[i] <= 'Z')
letter ++;
else if (str[i] >= '0' && str[i] <= '9')
digit ++;
else if (str[i] == ' ')
space ++;
else others ++;
}
printf("English character: %d\n", letter);
printf("digit character: %d\n", digit);
printf("space: %d\n", space);
printf("other character: %d\n", others);
}
3.以下次第 为求出并打印1000以内所有 水仙花数,请补齐代码。所谓水仙花数是指一个3位正整数,其各位 数字的破 方跟 等于 该正整数。比如 407 = 4* 4 * 4+0*0*0+7*7*7,故407是一个水仙花数.
#include <stdio.h>
int main()
{
int x, y, z, a[100], m, i = 0, j = 0;
printf("The special numbers are (in the arrange of 1000) . \n");
for( m=100; m<1000 ___________; m++)
{
x = m / 100;
y = m/10%10 ;
z = m %10;
if(x * 100 + y * 10 + z == x * x * x + y * y * y + z * z * z)
{ a[i] = m ; i++ ; }
}
for(j = 0; j < i; j++)
printf("%6d",a[j]);
printf("%\n");
return 0;
}
精选可编辑
展开阅读全文