指针卷.doc_第1页
指针卷.doc_第2页
指针卷.doc_第3页
指针卷.doc_第4页
指针卷.doc_第5页
已阅读5页,还剩14页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

一、 指针作业一、 选择题:1. 设*p, i ; 以下正确的语句是 (C ). A)*p=10; B) i=p; C) i=*p; D) p=2*p+1;2. 设char s10; int i; 以下正确的表达式是 (B )。 A) i+2; B) *(s+i); C) *(&s+i); D) *(s+)+i)3. 设char s10; *p=s; 以下不正确的表达式是 (B )。 A) p=s+5; B)s=p+s; C) s2=p4; D)*p=s0;4. 设char*s;以下正确的表达式是 (B )。 A) s= “computer” B) *s=“computer”; C) *s=“computer” D)*s=c;5. 设有语句:int a10=0,1,2,3,4,5,6,7,8,9,*p=a;,以下对a数组的元素正确的引用是 ( D )。 A) ap-a B) *9&ai) C)pi D)*(*a(a+i)6. 设有说明int(*ptr)M;其中ptr是 (C )。 A)M个指向整型变量的指针 B) 指向M个整型变量的函数指针 C) 一个指向具有M个整型元素的一维数组的指针 D) 具有M个指针元系的一维指针数组,每一个元素只能指向整型量7. 选择i的正确结果 (B )。 int i; char*s=”a045+045”b”; for (i=0;*s+;i+);A) 5 B) 8 C) 11 D) 128. 如下程序的执行结果是 (A )。 #include main() int i; char *s=”ann35b”; for(i=0;*s+;i+); printf(“i=%dn”,i); A) i=5 B) i=6 C) i=7 D) i=89.如下程序的执行结果是 (C )。 #include main() int i; char *s=”an”; for(i=0;si!=n;i+) printf(“%c,*(s+i); A) a B) a C) a D) a10. 如下程序的执行结果是 (B )。 #includ main() int i; char *s=”; for(i=0;si!=0;i+) printf(“%c”,*(s+i); A) ” B) a” C) “” D)不正确11.如下程序的执行结果是 ( A )。 #includ main() int i; char*s=”; for(i=0;si!=0;i+) printf(“%c”,*(s+i); A) ” B) a” C) “” D)不正确12. 如下执行的程序结果是 (B )。 #include main() static int a=1,2,3,4,5,6; int*p; p=a; *(p+3)+=2; ptintf(“%d,%dn”,*p,*(p+3); A) 1, 3 B) 1, 6 C) 3, 6 D) 1, 413. 如下程序的执行结果是 ( C )。 #include main() static int a4=(1,3,5,7,9,11,13,15,17,19,21,23); int(*p)4,i=1,j=2; p=a; printf(“%dn”,*(*(p+i)+j); A) 9 B) 11 C) 13 D) 1714.以下count函数的功能是统计substr在母串str中出现的次数,请选择正确的编号填空。 count(ahsr*str,car*substr) int i,j,k,num=0; for (i=0;_B_;i+) for(_B_,k=0;substrk=strj;k+,j+) if(substr_=0) num+; break; return(num); A) stri=substri B) stri!=0 C) stri=0 D) strisubstriA) j=j+1 B) j=I C) j=0 D)j=1A) k B) k+ C) k+1 D) +k15. 以下delspace函数的功能是删除字符串s中的所有空格(包括Tab)、回车符和换行符)。请选择正确的编号填空。 delspace(car*s) int i,t; char c80; for (i=0,t=0;_;i+) if(delspace(_) ct+=si; ct=0; strcpy(s,c); A) si B) !si C) si=0 D) si=0A) s+i B) *ci C) *(s+i) D) *(c+i)16. 以下delunu函数的功能是删除字符串s中的数字字符。请选择正确的编号填空。 delnum(char*a) int i,j; for(i=0.j=0;si!=0;i+) if(_) sj=si; j+; _; A) sj9 B) si9C) sj9 D) si9 A) sj=0 B) si=0C) sj+=”0 D) si+=017. 以下comp函数的功能是按词典顺序比较两个字符串s和t的大小,如果s大于t,则返回正值,等于则返回0,小则返回负值。请选择正确的编号填空。 comp(char *s,char *t) for(;*s=*t; ) if(*s=0) return(0); return(*s=*t); A) s+ B) t+ C) s+;t+ D) s+,t+18. 以下conj函数的功能是将两个字符串s和t连接起来,请选择正确的编号填空。 conj(char *s,char *t) char *p=s; while(*s) ; while(*t) *s= ; s+; t+; *s=0 A) s- B) s+ C) s D) *s A) *t B) t C) t- D) *t+ A) return(s) B) return(t) C) return(p) D) return(p-t)二、填空题1. 定义int a=1,2,3,4,5,6,*p=a;表达式(*+p)+的值是 。2. 以下程序的执行结果是 n1=1,n2=6 。 #include main() int a=1,2,3,4,5,6; int *p; int i; p=a; *(p+3)+=2; printf(“nl=%d,n2=%dn”,*p,*(p+3); 3. 以下程序的执行结果是 10 。 #include main() Int *p,*q,i=10; q=&i; p&q; printf(“%dn”,*p); 4. 以下程序的执行结果是 i=10 j=2 。 #include main() int i,j; int *p,*q; i=2; j=10; p=&i; q=&j; *p=10; *q=2; printf(“i=%d,j=%dn”,i,j); 5. 以下程序的执行结果是 5, 2 。 #include main() int i; int *p; p=&i; *p=2; p+; *p=5; printf(“%d,”,*p); p-; printf(“%dn”,*p); 6. 以下程序的执行结果是 i=15 。 #include main() Int *p,i; i=5; p=&i; i=*p+10; printf(“i=%dn”,i); 7. 以下程序的执行结果是 ch=f #include main() char s=”abcdefg”; char *p; p=s; printf(“ch=%cn”,*(p+5); 8. 以下程序的执行结果是 24 。 #include main() int a=2,3,4; int s,i,*p; s=1; p=a; for(i=0;i3;i+) s*=*(p+i); printf(“s=%dn”,s); 9. 以下程序的执行结果是 654321 。 #include main() int a=1,2,3,4,5,6,*p; for (p=&a5;p=a;p-) printf(“%d”,*p); printf(“n”); 10. 以下程序的执行结果是 12 。 #include main() int a12=1,2,3,4,5,6,7,8,9,10,11,12,*p4,i; for (i=0;i4;i+) pi=&ai*3; printf(“%dn”,p32); 11. 以下程序的执行结果是 6358 。 #include main() char ch25=“6934”,”8254”,*p2; int i,j,s=0; for (i=0;i2;i+) pi=chi; for (i=0;i0&pij=9;j+=2) s=10*s+pij-0; printf(“%dn”,s); 12. 以下程序的执行结果是 xbcdBCD 。 #include main() char *p1,*p2,str20=”xyz”; p1=”abcd”; p2=”ABCD”; strcpy(str+1 ,strcat(p1+1,p2+1); printf(“%s”,str); 13. 以下程序的执行结果是 a=9,b=6,c=3 。 swap(pt,pt2) int*pt1,*pt2; int i; i=*pt1; *pt1=*pt2; *pt2=i; exchange(q1,q2,q3) int*q1,*q2,*q3; if(*q1*q2)swap(q1,q2); if(*q1*q3)swap(q1,q3); if(*q2*q3)swap(q2,q3); main() int a,b,c; int*p1,*p2,*p3; p1=&a; p2=&b; p3=&c; *p1=3; *p2=6; *p3=9; exchange(p1,p2,p3); printf(“a=%d,b=%d,c=%dn”,a,b,c; 14. 设包含如下程序的文件名为myprog.c, 编译后健入命令:myprog one two three, 则执行结果是 one two three 。 #include main(int arec,char *argv) int i; for (i=1;iarec;i+) printf(“%s%”,argvi,(iarec-1)?”:n); 15. 下面的函数strcat(str1,str2)实现将字符串str2拼接到字符串str1后面的功能,请在程序的空白处填入一条语句或一个表达式。 char *strcat(str1.str2); char*str1,*str2; char*t=str1; while(_*str1_) strl+; while(_*str1+=*str2+_); return(t); 16. 下面的程序可以统计命令行第一参数中出现的字母的个数,请在程序中空白处填入一条语句或一个表达式。 #include #include main(argc,argv) int argc; char* argv; char*str; int count=0; if (argc2) exit(1); str= argv1 ; while (*str) if (isapha( *str+ ) count+; printf(“n字母个数:%dn”,count); 三、程序题1. 编写一个程序,接受用户输入的一行字符,以回车健结束,分别统计其中的大写字母、小写字母、空格、数字和其他字符的个数。源程序如下: #include main() int n1=0,n2=0,n3=0,n4=0,n5=0,i; char *p,str80; printf(“输入一行字符: “); i=0; while(stri=getchar()!=”n)i+; p=str; while(*p!=n) if(*p=A&*p=a&*p=0&*p=9) n4+; else n5+; p+; printf(“大 写 字 母 数:%d 小 写 字 母 数:%d空 格 数:%d数 字 数:%d其 他 数:%dn”,n1,n2,n3,n4,n5); 1.2. 编写一个程序,打印出下面的图形。 * * * * * * * *2. 源程序如下: #include main() int i,j; char*s; s=” * “; printf(“%sn”,s); for for(j=1;j=4-i;j+)printf(“”); for(j=1;j=2;i;j+)printf(“*”); for(j=1;j=2*i+1;j+)printf(“”); for(j=1;j=2;i;j+)printf(“*”); for(j=1;j=4-i;j+)printf(“”); printf(“n”); for(i=1;i=13;i+)printf(“*”); printf(“n”);3. 编写一个程序判定一个字符在一个字符串中出的次数,如果该字符不出现则返回0。源程序如下: #include #include char_count(char*s,char letter); main() char*str,c; printf(“输入一字符串:”); gets(str); printf(“输入一字符串:”); scanf(“%c”,&c); printf(“该字符在字符串中出现:%d次n”,char_count(str,c); char_cont(char*s,char letter) int count=0; while(*s) i(*s+= =letter) count+; return(count); 4. 编写一个程序,计算用户输入的起始时间终止时间之间相距的天数。二、 结构体和联合体一、选择题1. 在说明一个结构体变量时系统分配给它的存储空间是(D )。A) 该结构中第一个成员所需存储空间B) 该结构体中最后一个成员所需存储空间C) 该结构体中占用最大空间的成员所需存储空间D) 该结构体中所有成员所需存储空间的总和2. 在说明一个联合体变量时系统分配给它的存储空间是(C )。A) 该联合体中第一成员所需存储空间B) 该联合体中最后一个成员所需存储空间C) 该联合体中占用最大存储空间的成员所需存储空间D) 该结构体中所有成员所需存储空间的总和3. 联合体类型在任何给定时刻, ( A )。A) 所有成员一直驻留在结构中 B) 只有一个成员驻留在结构中C) 部分成员驻留在结构中 D) 没有成员驻留在结构中4. 使用联合体union的目的是 (A )。 A) 将一组数据作为一个整体,以便于其中的成员共享一存储空间 B) 将一组具有相同数据类型的数据作为一个整体,以便于其中的成员共享同一存储空间 C) 将一组相关数据作为一个整体,以便于在程序中使用 D) 将一组具有相同数据类型的数据作为一个整体,以便于在程序中使用5. 以下typedef的叙述不正确的是(B )。 A) 用typedef可以定义各种类型名,但不能用来定义变量 B) 用typedef可以增加新的类型 C) 用typedef只是将已存在的类型用一个新的名称来代表 D) 使用typedef便于程序的通用6. 以下关于枚举的叙述不正确的是(D )。 A) 枚举变量只能取对应枚举类型的枚举元素表中的元素 B) 可以在定义枚举类型时对枚举元素进行初始化 C) 枚举元素表中的元素有先后次序,可以进行比较 D) 枚举元素的值可以是整数或字符串7. 在以下程序段中,枚举变量c1和c2的值分别是 (D )和 ( )。 main() enum color(red,yellow,blue=4,green,while)c1,c2; c1=yellow; c2=white; printf(“%d,%dn”,c1,c2); A.) 1 B) 3 C) 5 D) 68. 若有以下程序说明和语句: struct worker int no; char*name; work,*p=&work;则以下引用方式不正确的是 ( D)。 A) work.no B) (*p).no C) p-no D) work-no9. 以下程序执行后的正确结果是 (B )。 struct tree int x; char*s; t; func(stuct tree t) (t.x=10 t.x=”computer”; return(0); main() t.x=1; t.s=”minicomputer”; func(t); printf(“%d,%sn”,t,x,t,s); A) 10,computer B) 1,minicomputer C) 1,computer D) 10,minicomputer10. 有如下定义: struct date int year,month,day; ; struct worklist char name20; char sex; strct date birthday; person;对结构体变量penson的出生年份进行赋值时,下面正确的赋值语句是 (C)。 A) year=1958 B) birthday.year=1958 C) peson.birthday.yeqr=1958 D) person.year=195811. 在如下结构体中,不正确的是 ( B )。 A) struct student B) struct stud20 int no; int no; char name10; char name10; float score; float score; C) struct student D) struct int no; int no; char name10; char name10; float score; float score; stud20; stud100;12. 以下函数定义不正确的是 ( D )。 A) stuct tree func(s) B) int*func(s) stuct tree s; char s; C) sturct tree*func(s) D) int *func(s) char*s; char*s10; 13. 正确的K值是 ( C )。 enum a,b=5,c,d=4,ek; k=e; A) 3 B) 4 C) 5 D) 614. 以下程序的执行结果是 ( B )。 main() union int x; struct char c1; char c2; b; a; a.x=0x1234 printf(“%x,%xn”,a.b.c1,a.b.c2); A) 12,34 B) 34,12 C) 12,00 D) 34,0015. 以下程序的执行结果是 (B )。 main() union char s2; int i; a; a.i=0x1234; printf(“%x,%xn”, a.s0,a.s1); A) 12,34 B) 34,12 C) 12.00 D) 34,00二、填空题1. 以下程序执行的结果是 24 。 typedef struct long x2; int y4; char z8; MYTYPE; MYTYPE a; main() printf(“%dn”,sizeof(a); 2. 有如下定义: struct int x; char*y; tab21,”ab”,2,”cd”,*p=tab;则:表达式*py的结果是( a ),表达式*(+p)-y的结果是( c )。3. 有如下定义: struct int x; int y; s2=1,2,3,4,*p=s;则:表达式+p-x的结果是( 2 ),表达式 (+p) -x的结果是( 3 )。4. 以下程序的执行结果是 10,X 。 struct stru int x; char c; ; main() struct stru a=10,x; func(a); printf(“%d,%cn”,a.x.a.c); func(struct stru b) b.x=0; b.c=y; 5. 以下程序的执行结果是 20.y 。 struct stru int x; char c; ; main() struct stur a=10,x,*p=&a; func(p); printf(“%d,%cn”,a.x,a.c); func(struct stru*b) b-x=20; b-c=y; 6. 以下程序的执行结果是 39,0,38,0 。 main() union int i2; long k; char c4; r,*p=&r; p-i0=0x39; p-ii=ox38; printf(“%x, %x, %x, %xn”, p-c1,p-c2,p-c3); 7. 以下程序的执行结果是 8 。 typedef union long x2; int y4; char z8; MYTYPE a; main() printf(“%dn”,sizeof(a); 8. 以下程序的执行结果是 1,2,30,41 。 sturct st int x; int*y; *p; int s=10,20,30,40; struct st a=1,&s0,2&s1,3,&s2,4,&s3; main() p=a; printf(“%d,”,p-x); printf(“%d,”,(+p)-x); printf(“%d,”,*(+p-y); printf(“%dn”, +(*(+p)-y); 9. 以下程序的执行结果是 4,8 。 #includestdio.h) main() union EXAMPLE struct int x;int y; in; int a; int b; e; e.a=1;e.b=2; e.in.x=e.a*e.b; e.in.y=e.a+e.b; printf(“%d,%dn”,e.in.x,e.in.y); 10. 以下程序的执行结果是 4 。 #includestdio.h) main() struct equip unsigned a:2; unsigned b:3; unsigned c:1; unsigned d:4; unsigned e:3; unsigned unused:3; ; union struct equip eq; unsigned i; abc; abc.i=255; printf(“%dn”,abc.eq.d+1); 三、 程序题(涉及数据结构,暂时不做)1. 说明一个枚举类型enum month, 它的枚举元素为Jan,Feb,Dec。编写一个显示上一个月名称的函数last_month(),例如输入jan,则显示dec,再编写一个函数printfmon(),对指定的类型为enum month的变量打印出它的枚举元素,即三个字母,

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论