a:
d的结果为(A)。
A、1B、2C、3D、4
10.要判断char型变量m是否是数字,可以使用下列表达式(B)。
A、0<=m&&m<=9B、‘0’<=m&&m<=’9’
C、“0”<=m&&m<=”9”D、前面三个答案均是错误的
11.C语言中形参的缺省存储类别是(A)。
A、自动(auto)B、静态(static)C、寄存器(register)D、外部(extern)
12.下列对数组操作不正确的语句是(D)。
A、inta[5];B、charb[]={‘h’,’e’,’l’,’l’,’o’};
C、inta[]={2,3,4,5};D、charb[3][]={1,2,3,4,5,6};
13.设有数组定义:
chararray[]="China";则数组array所占的空间为(C)。
A、4个字节B、5个字节C、6个字节D、7个字节
14.若用数组名作为函数调用的实参,传递给形参的是(A)
A、数组的首地址B、数组第一个元素的值
C、数组中全部元素的值D、数组元素的个数
15.说明语句”int(*p)();”的含义是(B)。
A、p是一个指向一维数组的指针变量
B、p是一个指向函数的指针,该函数的返回值是一个整型
C、p是指针变量,指向一个整型数据
D、以上都不对
16.设i,j,k均为int型变量,执行完下面的for循环后,k的值为(A)
for(i=0,j=10;i<=j;i++,j--)k=i+j;
A、10B、9C、8D、7
17.有以下程序
main()
{
chara[]="programming",b[]="language";
char*p1,*p2;
inti;
p1=a;p2=b;
for(i=0;i<7;i++)
if(*(p1+i)==*(p2+i))
printf("%c",*(p1+i));
}
输出结果是(D)。
A、gmB、rgC、orD、ga
18.定义结构体的关键字是(C)。
A、unionB、enumC、structD、typedef
19.若要用下面的程序片段使指针变量p指向一个存储整型变量的动态存储单元:
int*p;
p=__________malloc(sizeof(int));
则应填入(D)。
A、intB、inst*C、(*int)D、(int*)
20.在文件使用方式中,字符串″rw″表示(D)。
A、打开一个已存在的二进制文件,只能读取数据
B、打开一个文本文件,只能写入数据
C、打开一个已存在的文本文件,只能读取数据
D、打开一个二进制文件,能读取写入数据
二、判断题。
1.C语言的一个特点是可以对计算机硬件进行操作。
(√)
2.函数中的局部变量都是动态存储。
(ⅹ)
3.自增运算符(++)或自减运算符(--)只能用于变量,不能用于常量或表达式。
(√)
4.函数的定义可以嵌套,但函数的调用不可以嵌套。
(ⅹ)
5.do-while循环中,根据情况可以省略while。
(ⅹ)
6.形参时虚拟的,不占用存储单元。
(ⅹ)
7.用户若需要调用标准库函数,调用前必须重新定义。
(ⅹ)
8.文件指针是结构体类型,用符号file来表示。
(ⅹ)
9.在实际编程中,do-while循环完全可以用for循环替换。
(√)
10.if语句,switch语句可以嵌套,而且嵌套的层数没有限制。
(ⅹ)
三、填空题。
1.“*”称为___指针_____运算符,“&”称为___地址____运算。
2.C语言中,用基本类型变量作为函数参数只能进行值传值,而通过数组(指针、全局变量)等类型变量作为函数参数可以实现地址传值。
3.C语言中,定义结构体类型的关键字是struct,文件(FILE)类型由系统在______stdio.h_________头文件中的定义。
4.设有年份变量year,写出判断year是否是闰年的表达式(year%4==0&&year%100!
=0)||(year%400==0)。
5.C语言中putchar(c)函数的功能是____将变量c中的字符显示到屏幕上_________。
四、写出程序运行结果。
1.#include
main()
{
charch;
ch=getchar();
switch(ch)
{
case65:
printf(“%c”,‘A’);
case66:
printf(“%c”,’B’);
default:
printf(“%s\n”,”other”);
}
}
如程序可以正常运行,当从键盘输入字母A时,输出结果为ABother。
2.以下程序的执行结果是_____iilovcprogram_______。
#include
main()
{
inti=5;
charc[20]="ilovecprogram";
do
{
c[i]=c[i-1];
}while(--i>0);
puts(c);
}
3.#include
main()
{
inti=0,j=0;
while(i<10)
i++;
While(j++<10);
Printf(“i=%d,j=%d\n”,i,j);
}
运行结果是i=10,j=11。
4.执行以下程序段,输出的结果为7。
voidswap(int*a,int*b)
{
int*t;
t=a;
a=b;
b=t;
}
main()
{
intx=7,y=5,*p=&x,*q=&y;
swap(p,q);
printf("%d\t%d\n",*p,*q);
}
五、程序设计题。
1.编程实现,从键盘接收一个年份,判断该年份是否是闰年,要求判断闰年使用函数实现。
#include"stdio.h"
intfunction1(int);
intmain()
{
intyear,flag=0;
puts("请输入查询年份");
scanf("%d",&year);
flag=function1(year);
if(flag==1)
{
printf("%d是闰年\n",year);
}
else
{
printf("%d不是闰年\n",year);
}
return0;
}
intfunction1(intyear)
{
intt=0;
if(year%4==0)
{
if(year%100!
=0)
{
t=1;
}
else
{
if(year%400==0)
{
t=1;
}
else
{
t=0;
}
}
}
else
{
t=0;
}
returnt;
}
2.建立一个链表,每个节点包含的成员为:
学号(num),成绩(score),用malloc函数开辟新结点,链表包含10个结点,从键盘输入数据,然后把数据输出D盘test.txt文件中。
#include"stdio.h"
#include"stdlib.h"
#defineMAX10
structstudent
{
longnum;
floatscore;
structstudent*next;
};
structstudent*creat()
{
inti;
structstudent*p1,*p2,*head;
head=p1=p2=(structstudent*)malloc(sizeof(structstudent));
scanf("%ld,%f",&p1->num,&p1->score);
for(i=0;i{
p1=(structstudent*)malloc(sizeof(structstudent));
scanf("%ld,%f",&p1->num,&p1->score);
p2->next=p1;
p2=p1;
}
p2->next=NULL;
return(head);
}
voidtofile(structstudent*head)
{
FILE*fp;
structstudent*p1;
p1=head;
if((fp=fopen("D:
\\test.txt","w"))==NULL)
{
printf("cannotopenfile!
\n");
exit(0);
}
while(p1!
=NULL)
{
fprintf(fp,"%ld\t%f\n",p1->num,p1->score);
p1=p1->next;
}
fclose(fp);
}
intmain()
{
structstudent*p;
p=creat();
tofile(p);
return0;
}
3.编程实现将文本文件file1.dat中的内容复制到文本文件file2.dat中去。
#include"stdio.h"
voidmain()
{
charch;
FILE*fp1,*fp2;
fp1=fopen("file1.dat","r");
fp2=fopen("file2.dat","w");
ch=fgetc(fp1);
while(ch!
=EOF)
{
fputc(ch,fp2);
ch=fgetc(fp1);
}
fclose(fp1);
fclose(fp2);
}
4.从键盘上输入10个数存入一维数组中,求这10数中的最大值与最小值并输出。
#include"stdio.h"
intmain()
{
inta[10],max,min;
for(i=0;i<10;i++)
scanf("%d",&a[i]);
max=a[0];
for(i=1;i<10;i++)
if(a[i]>max)
max=a[i];
min=a[0];
for(i=1;i<10;i++)
if(a[i]min=a[i];
printf("%d%d",max,min);
return0;
}