文档详情

2016C语言习题全集及答案:指针02.doc

发布:2017-07-02约字共9页下载文档
文本预览下载声明
第七单元 指 针 读程序题,写出程序运行的结果。 1、 #include stdio.h void main() { int *p1,*p2,*p; int a=5,b=8; p1=a; p2=b; if(ab) { p=p1; p1=p2; p2=p;} printf(%d,%d\n,*p1,*p2); printf(%d,%d\n,a,b); } 2、 void ast(int x,int y,int *cp,int *dp) { *cp=x+y; *dp=x-y; } void main() { int a,b,c,d; a=4; b=3; ast(a,b,c,d); printf(%d,%d\n,c,d); } 3、 void main() { int a[]={2,4,6,8,10}; int y=1,x,*p; p=a[1]; for(x=0;x3;x++) y+=*(p+x); printf(y=%d\n,y); } 4、 void main() { int a[2][3]={1,2,3,4,5,6}; int m,*ptr; ptr=a[0][0]; m=(*ptr)*(*(ptr+2))*(*(ptr+4)); printf(%d\n,m); } 5、 void prtv(int * x) { printf(%d\n,++*x); } void main() { int a=25 ;prtv(a); } 6、 void fun(int *a, int *b, int *c) { int *temp; temp=a; a=b; b=temp; *temp=*b, *b=*c; *c=*temp; } void main() { int a,b,c,*p1,*p2,*p3; a=5; b=7; c=3; p1=a; p2=b; p3=c; fun(p1,p2,p3); printf(%d,%d,%d\n,a,b,c); } 7、 #include stdio.h void main() { static int a[2][3]={1,3,5,2,4,6}; int *add[2][3]={*a,*a+1,*a+2,*(a+1),*(a+1)+1,*(a+1)+2}; int **p,i; p=add[0]; for(i=0;i6;i++) { printf(%d ,**p); p++;} printf(\n); } 8、 void main() { char s[]=ABCD,*p; for(p=s+1;ps+4;p++) printf(%s\n,p); } 9、 int fa(int x) { return x*x; } int fb(int x) { return x*x*x; } int f(int (*f1)(),int (*f2)(),int x) { return f2(x)-f1(x); } void main() { int i; i=f(fa,fb,2); printf(“%d\n”,i); } 10、 #include stdio.h #include string.h void main() { char b1[8]=abcdefg,b2[8],*pb=b1+3; while (--pb=b1) strcpy(b2,pb); printf(%d\n,strlen(b2)); } 11、 char cchar(char ch) { if (ch=‘A’ch=‘Z) ch=ch-‘A+‘a; return ch; } void main() { char s[]=ABC+abc=defDEF,*p=s; while(*p) { *p=cchar(*p); p++; } printf(%s\n,s); } 12、 void main( ) { int a[5]={2,4,6,8,10},*p,* *k; p=a; k=p; printf(%d,*(p++)); printf(%d\n,* *k); } 13、 funa(int a,int b ) { return a+b;} funb(int a,int b ) { re
显示全部
相似文档