C语言程序设计练习题第3部分答案.docx

上传人:b****3 文档编号:5404093 上传时间:2022-12-16 格式:DOCX 页数:16 大小:27.17KB
下载 相关 举报
C语言程序设计练习题第3部分答案.docx_第1页
第1页 / 共16页
C语言程序设计练习题第3部分答案.docx_第2页
第2页 / 共16页
C语言程序设计练习题第3部分答案.docx_第3页
第3页 / 共16页
C语言程序设计练习题第3部分答案.docx_第4页
第4页 / 共16页
C语言程序设计练习题第3部分答案.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

C语言程序设计练习题第3部分答案.docx

《C语言程序设计练习题第3部分答案.docx》由会员分享,可在线阅读,更多相关《C语言程序设计练习题第3部分答案.docx(16页珍藏版)》请在冰豆网上搜索。

C语言程序设计练习题第3部分答案.docx

C语言程序设计练习题第3部分答案

C程序设计语言练习题

第三部分

63.已知:

intx;则下面说明指针变量pb的语句是正确的。

A)intpb=&x;B)int*pb=x;C)int*pb=&xD)*pb=*x;

64.有如下程序段:

int*p,a,b=1;

p=&a;*p=10;a=*p+b;

执行该程序段后,a值是。

A)12B)11C)10D)编译出错

65.若有说明:

inti,j=2,*p=&i;,则能完成i=j赋值功能的语句是。

A)i=*p;B)*p=*&j;C)i=&j;D)i=**p;

66.已知:

inta,*p=&a;则为了得到变量a的值,下列错误的表达式为______。

A)*&pB)*pC)p[0]D)*&a

67.已知staticinta[2][3]={2,4,6,8,10,12};正确表示数组元素地址的是__。

A)*(a+1)B)a[1]+2C)a[1]+3D)a[0][0]

68.已知inta[3][4],*p=*a;p+=6;那么*p和______的值相同。

A)*(a+6)B)*(&a[0]+6)C)*(a[1]+2)D)*(&a[0][0]+6)

69.已知说明int(*p)[M];其中p是______。

A)M个指向整型变量的指针

B)指向M个整型变量的函数指针

C)一个指向具有M个整型元素的一维数组的指针

D)具有M个指针元素的一维指针数组,每个元素都只能指向整型变量

70.若有定义和语句:

intc[4][5],(*cp)[5];cp=c;则对c数组元素的引用正确的是哪个?

A)cp+1B)*(cp+3)C)*(cp+1)+3D)*(*cp+2)

71.设有以下定义:

inta[4][3]={1,2,3,4,5,6,7,8,9,10,11,12};

int(*prt)[3]=a,*p=a[0];

则下列能够正确表示数组元素a[1][2]的表达式是__________。

A)*((*prt+1)[2])B)*(*(p+5))C)(*prt+1)+2D)*(*(a+1)+2)

72.若有以下定义和语句:

intw[2][3],(*pw)[3];pw=w;

则对w数组元素的非法引用是_________。

A)*(pw[0]+2)B)*(pw+1)[2]C)pw[0][0]D)*(pw[1]+2)

73.若有以下说明和定义:

fun(int*c){…}

voidmain()

{int(*a)(int*)=fun,*b(),w[10],c;

:

}

在必要的赋值之后,对fun()函数的正确调用语句是______。

A)a=a(w);B)(*a)(&c);C)b=*b(w);D)fun(b);

74.已知double*p[6];它的含义是______。

A)p是指向double类型变量的指针B)p是double类型数组

C)p是double类型指针数组D)p是double类型数组指针

75.设有定义:

intn=0,*p=&n,**q=&p;则______是正确的赋值语句。

A)p=1;B)*q=2;C)q=p;D)*p=5;

76.以下选项中,错误的赋值是_________

A)chars1[10];s1=”Ctest”;

B)chars2[]={‘C’,‘t’,‘e’,‘s’,‘t’};

C)chars3[20]=”Ctest”;

D)char*s[4]={”Ctest\n”};

77.若有定义和语句:

int**pp,*p,a=10,b=20;

pp=&p;p=&b;printf(“%d,%d\n”,*p,**pp);

则输出的结果是______。

A)10,20B)10,10C)20,10D)20,20

78.以下程序编译连接后生成的可执行文件是ex1.exe,若运行时输入带参数的命令行是:

ex1abcdefg10<回车>,则运行的结果是什么?

9

#include

main(intargc,char*argv[])

{inti,len=0;

for(i=1;i

printf("%d\n",len);

}

79.说明语句int(*p)();的含义是______。

A)p是一个指向一维数组的指针变量

B)p是一个指针变量,指向一个整型数据

C)p是一个指向函数的指针,该函数的返回值是一个整型数据

D)以上都不对

80.说明语句int*(*p)();的含义是______。

A)p是一个指向int型数组的指针

B)p是一个指针变量,它构成了指针数组

C)p是一个指向函数的指针,该函数的返回值是一个整型数据

D)p是一个指向函数的指针,该函数的返回值是一个指向整型数据的指针

81.说明语句void*f();的含义是______。

A)函数f的返回值是一个通用型的指针

B)函数f的返回值可以是任意的数据类型

C)函数f没有返回值

D)指针f指向一个函数,该函数无返回值

82.已知char**s;正确的语句是_______。

A)s=“book”B)*s=“book”;

C)**s=“book”D)strcpy(*s,“book”);

83.阅读以下函数,说出每个函数的作用

(1)计算1+2+3+.....+n

sum(intn)

{if(n==1)return1;

elsereturnsum(n-1)+n;

}

(2)计算字符串的长度

intstrtry(char*s)

{if(*s==’\0’)return0;

elsereturnstrtry(s+1)+1;

}

(3)有n个元素的数组逆置

voidchange(int*a,intn)

{intt;

t=*a;*a=*(a+n-1);*(a+n-1)=t;

if(n>2)change(a+1,n-2);

}

(4)字符串的长度加1

ABC(char*ps)

{char*p;

p=ps;

while(*p++);

returnp-ps;

}

84.对于基类型相同的两个指针变量之间,不能进行的运算是______。

A)

85.不合法的main函数命令行参数表示形式是

A)main(inta,char*c[])B)main(intarc,char**arv)

C)main(intargc,char*argv)D)main(intargv,char*argc[])

86.写出下面各程序段的输出结果

(1)

staticchara[]=”Basic”;

char*p;

for(p=a;p

for(p=a;p

Basic

asic

sic

ic

c

B

a

s

i

c

(2)a=36b=16c=19

voidmain()

{inta=1,b=2,c;

c=func(a,&b);

b=func(c,&a);

a=func(b,&c);

printf("a=%d,b=%d,c=%d",a,b,c);

}

intfunc(inta,int*p)

{a++;

*p=a+2;

return(*p+a);

}

 

(3)2143

voidfun(int*x,int*y)

{printf(“%d%d”,*x,*y);

*x=3;

*y=4;

}

main()

{intx=1,y=2;

fun(&y,&x);

printf(“%d%d”,x,y);

}

(4)5

ss(char*s)

{char*p=s;

while(*p)p++;

return(p-s);

}

main()

{char*a=“abded”;

inti;

i=ss(a);

printf(“%d\n”,i);

}

 

(5)0

voidfun(int*n)

{while((*n)--);

printf(“%d”,++(*n));

}

main()

{inta=100;

fun(&a);

}

(6)24

main()

{inta[5]={2,4,6,8,10},*p,**k;

p=a;k=&p;

printf(“%d”,*(p++));

printf(“%d\n”,**k);

}

(7)9

main()

{inta[2][3]={1,3,5,7,9,11},*s[2],**pp,*p;

s[0]=a[0],s[1]=a[1];

pp=s;

p=(int*)malloc(sizeof(int));

**pp=s[1][1];

p=*pp;

printf(“%d\n”,*p);

}

(8)字符串的长度

func(charstr[])

{intnum=0;

while(*(str+num)!

=‘\0’)

num++;

return(num);

}

main()

{charstr[10],*p=str;

gets(p);

printf(“%d\n”,func(p));

}

(9)6385

main()

{charch[2][5]={“6934”,“8254”},*p[2];

intI,j,s=0;

for(I=0;I<2;I++)

p[I]=ch[I];

for(I=0;I<2;I++)

for(j=0;p[I][j]>‘0’&&p[I][j]<=‘9’;j+=2)

s=10*s+p[I][j]-‘0’;

printf(“%d\n”,s);

}

(10)4

intfa(intx)

{returnx*x;}

intfb(intx)

{returnx*x*x;}

intf(int(*f1)(int),int(*f2)(int),intx)

{return(*f2)(x)-(*f1)(x);}

main()

{inti;

i=f(fa,fb,2);printf("%d\n",i);

}

87、填写程序

(1)下列程序输出数组中的最大值,由s指针指向该元素

main()

{inta[10]={6,7,2,9,1,10,5,8,4,3},*p,*s;

for(p=a,s=a;p-a<10;p++)

if(*p>*s)s=p;

printf(“Themax;%d”,*s);

}

(2)函数sstrcmp()的功能是对两个字符串进行比较。

当s所指字符串和t所指字符串相等时,返回值为0;当s所指字符串大于t所指字符串时,返回值大于0;当s所指字符串小于t所指字符串时,返回值小于0(功能等同于库函数strcmp())。

intsstrcmp(char*s,char*t)

{while(*s&&*t&&*s==*t){s++;t++;}

return*s-*t;

}

(3)下面的程序完成的功能是:

从键盘输入一行字符,反序输出。

#include

structnode{chardata;structnode*link;}*head;

main()

{charch;structnode*p;

head=NULL;

while((ch==getchar())!

=’\n’)

{p=(structnode*)malloc(sizeof(structnode));

p->data=ch;

p->link=___head___;

head=___p____;

}

____p=head______;

while(p!

=NULL)

{printf(“%c”,p->data);____p=p->link______;}

}

(4)以下程序输入10本书的名称和单价,按照单价进行排序后输出。

#defineNUM10

structbook{charname[20];intprice;};

main()

{structbookterm,books[NUM];

intcount;

for(count=0;count

{printf(“Pleaseenterbooknameandprice.book%d=”,count+1);

scanf(“%s%d%*c”,_books[count].name,&books[count].price_);

}

sortbook(books,NUM);

printf(“--------------BOOKLIST---------\n”);

for(count=0;count

printbook(_books+count或&books[count]___);

}

sortbook(structbook*pbook,intcount)

{inti;

structbooktemp,*q,__*pb,*pend=pbook+count____;

for(i=0;i

{pb=pbook+i;

for(q=pb;q

if(q->price>pb->price)__pb=q__

___temp=*pb;*pb=*(pbook+i);*(pbook+i)=temp;__;

}

}

printbook(structbook*pbook)

{printf(“%-20s%6d\n”,pbook->name,pbook->price);}

88.以下对结构体类型变量的定义中,不正确的是。

A)typedefstructaaB)#defineAAstructaa

{intn;AA{intn;

floatm;floatm;

}AA;}td1;

AAtd1;

C)structD)struct

{intn;{intn;

floatm;floatm;

}aa;}td1;

structaatd1;

89.对于设有下列说明,则不正确的是______。

structex

{intx;floaty;charz;}example;

A)struct是结构体类型的关键字B)example是结构体类型名

C)x,y,z都是结构体成员名D)structex是结构体类型

90.以下选项中不能正确把c1定义成结构体变量的是。

A)typedefstructB)structcolorc1

{intred;{intred;

intgreen;intgreen;

intblue;intblue;

}COLOR;};

COLORc1;

C)structcolorD)struct

{intred;{intred;intgreen;

intgreen;intblue;

intblue;}c1;

}c1;

91.已知:

structsk

{inta;floatb;

}data,*p;

若有p=&data,则对data中成员a的正确引用是________。

A)(*p).data.aB)(*p).aC)p->data.aD)p.data.a

 

92.若有说明:

typedefstruct

{intn;charc;doublex;}STD;

则能正确定义结构体数组并赋初值的语句是。

A)STDtt[2]={{1,'A',62},{2,'B',75}};

B)STDtt[2]={1,"A",62,2,"B",75};

C)structtt[2]={{1,'A'},{2,'B'}};

D)structtt[2]={{1,"A",62.5},{2,"A",75.0}};

93.有说明:

structperson{charname[9];intage};

structpersonclass[5]={"Joju",17,"Paul",19,"Mary",18,"Adam",16};

能输出字母M的语句是____。

A)printf(“%c\n”,class[3].name);

B)printf(“%c\n”,class[3].name[1]);

C)printf(“%c\n”,class[2].name[1]);

D)printf(“%c\n”,class[2].name[0]);

94.下列程序的输出结果是__6__。

structabc

{inta,b,c;};

main()

{structabcs[2]={{1,2,3},{4,5,6}};intt;

t=s[0].a+s[1].b;

printf(“%d”,t);

}

95.有以下说明和定义语句:

structstudent{intage;charnum[8];};

structstudentstu[3]={{20,"200401"},{21,"200402"},{19,"200403"}};

structstudent*p=stu;

引用结构体变量成员的错误表达式是______。

A)(p++)->numB)p->numC)(*p).numD)stu[3].age

96.当说明一个结构体变量时系统分配给它的内存空间是。

A)各成员所需内存量的总和B)结构中第一个成员所需内存量

C)成员中占内存量最大者所需的容量D)结构中最后一个成员所需内存量

97.当说明一个共用体变量时系统分配给它的内存空间是。

A)各成员所需内存量的总和B)结构中第一个成员所需内存量

C)成员中占内存量最大者所需的容量D)结构中最后一个成员所需内存量

98.有以下说明和定义语句:

structstudent{intnum,age;};

structstudentstu[3]={{1001,20},{1002,19},{1003,21}};

structstudent*p=stu;

错误表达式是______。

A)(p++)->numB)p->ageC)(*p).numD)p=&stu.age

99.已知学生结构为:

structstudent{intno;charname[20];charsex;

struct{intyaer,month,day;}birth;

}s;

以下______是正确的赋值方式。

A)year=1984;month=11;day=11;

B)birth.year=1984;birth.month=11;birth.day=11;

C)s.year=1984;s.month=11;s.day=11;

D)s.birth.year=1984;s.birth.month=11;s.birth.day=11;

100.若有以下程序段:

structdent{intn;int*m;};

inta=1,b=2,c=3;

structdents[3]={{101,&a},{102,&b},{103,&c}};

structdent*p=s;

则以下表达式中值为2的是_____。

A)(p++)->mB)*(p++)->mC)(*p).mD)*(++p)->m

101.定义:

typedefARRAY1[10];

则整型数组a[10]、b[10]、t[10]可以定义为__ARRAYa,b,c;_____。

102.若已建立下面的链表结构,指针、分别指向图中所示结点,则不能将所指的结点插入到链表尾的一组语句是__。

A)q->next=NULL;p=p->next;p->next=q;

B)p=p->next;q->next=p->next;p->next=q;

C)p=p->next;q->next=p;p->next=q;

D)p=(*p).next;(*q).next=(*p).next;(*p).next=q;

103.如何定义如下形式的链表?

structxxxx

{intnum;charname[20];intage;charaddr[20];

structxxxx*next;

};

104.若要使STPs;等价于char*s;,应进行如下说明。

A)typedefSTPchar*s;B)typedef*charSTP

C)typedrfSTP*char;D)typedefchar*STP;

105.若有如下定义,则变量a所占的内存字节数是_10__

.uoionU{charst[6];inti;longl;};

structA{intc;unionUu;}a;

106.设有定义:

enumt1{a1,a2=7,a3,a4=15}time;

则枚举常量a1和a3的值分别是___0_8__。

107.以下枚举类型的定义中正确的是_______。

A)enuma={one,two,three};

B)enuma{one,two,three};

C)enuma={“one”,“two”,“three”};

D)enuma{“one”,“two”,“three”};

108.设inti=2,j=1,k=3;表达式i&&(i+j)&k|i+j的值为___1____。

109.设intb=2;表达式(b<<2)/(b>>1)的值是___8____。

110.C语言可以处理的文件类型是_________。

A)文本文件和数据文件B)文本文件

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 幼儿教育 > 育儿理论经验

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1