C语言考试选择题-PTA

1.int c[]={1, 3, 5};int **(一个星号)k=c+1;printf("%d",*++k)输出的结果是:C

A.3 B.4 C.5 D.6

2.如果二进制文件a.dat已经存在,现在要求写入全新数据,应以()方式打开。B

A.“w” B.“wb” C.“w+” D.“wb+”
首先是dat(二进制)文件,必须带b。全新文件,不能有+号,故选B

3.直接使文件指针重新定位到文件读写的首地址的函数是()C

A.ftell()函数 B.fseek()函数 C.rewind()函数 D.ferror()函数

4.执行下列程序:
#define MA(x,Y) (X*Y)
i = 5;
i = MA( i , i+1 ) - 7;
变量i的值应为()

A.19 B.30 C.1 D.23
#define 宏定义只是替换,MA(i,i+1)替换成x = i,y = i + 1。执行 x * y == i * i + 1(注意此处i + 1没有括号)。所以结果是26,最终结果是19

5.在一个单链表head中,若要在指针p所指结点后插入一个q指针所指结点,则执行()D

A.p->next=q->next; q->next=p;
B.q->next=p->next; p=q;
C.p->next=q->next; p->next=q;
D.q->next=p->next; p->next=q;

6.若p1、p2都是整形指针,p1已经指向变量x,要使p2也指向x,()是正确的。A

A.p2 = p1;
B.p2 = * *p1;
C.p2 = &p1;
D.p2 = *p1;

7.有如下定义
struct student{
char name[10];
int age;
char gender;
}std[3], *p=std;
则以下各输入语句中错误的是:D

A.scanf("%d" ,&(*p) .age );
B.scanf("%c" ,&std[0] .gender);
C.scanf("%c" ,&(p->gender));
D.scanf("%s" ,&std.name);
本题考核的知识点是结构型数组的应用。选项A中“&(*p).age”代表的是std[0]age的地址,是正确的,选项B也是正确的,选项C先用指针变量引用结构型的成员name,然后取它的地址,也是正确的,选项D中的“std.name"是错误的引用,因为std是数组名,代表的是数组的首地址,地址没有成员“name”。所以B选项为所选。

8.以下程序运行结果是( )C
int main() {
char a[ ] = " 123456789 " , *p = a ;
int i = 0 ;
while ( *p ) {
if ( i % 2 == 0 ) *p = ’ ! ’ ;
i ++ ; p ++ ; }
puts ( a ) ;
return 0 ;

A.1!3!5!7!9
B.!1!3!5!7!9!
C.!2!4!6!8!
D.2!4!6!8

9.以下程序运行结果是()A
int main() {
char str[ ] = " ABCDEFG ";
char *p1, *p2;
p1 = " abcd "; p2 = " efgh ";
strcpy (str+1, p2+1 );
strcpy (str+3, p1+3 );
printf("%s", str);
return 0; }

A.Afgd
B.AfgdEFG
C.Abfhd
D.Afghd
str+1=“BCDEFG”
p2+1=“fgh”
strcpy(str+1,p2+1)结果str[]=“Afgh”
str+3=“h”
p1+3=“d”
strcpy(str+3,p1+3)结果str[]=“Afgd”

10.阅读以下函数,此函数的功能是( )D
int fun( char *s1, char * s2 ) {
int i = 0 ;
while( s1[ i ] == s2[ i ] && s2[ i ] != ‘\0’ ) i++;
return ( s1[ i ] = = ‘\0’ && s2[ i ] == ‘\0’ ) ; }

A.将s2所指字符串赋给s1
B.比较s1和s2所指字符串的大小,若s1比s2的大,函数值为1,否则函数值为0
C.比较s1和s2所指字符串的长度,若s1比s2的长,函数值为1,否则函数值为0
D.比较s1和s2所指字符串是否相等,若相等,函数值为1,否则函数值为0
在函数fun()中有两个字符型指针变量s1和s2,在函数中程序执行while循环,该循环退出条件有两个:一个是s1[i]!=s2i:第二个是s1[i]和s2[i]相等均为“\0”(两个字符串相等)。循环退出后,执行return语句,即两个字符串相等则返回1,不相等则返回0。所以, D选项为所选。

猜你喜欢

转载自blog.csdn.net/qq_44256227/article/details/89607219