AaronPlay 2020-06-07
#include <stdio.h> int main() { int *p,a,c=3; float *q,b; p=&a; q=&b; printf("Please Input the Value of a,b:"); scanf("%d,%f",p,q); printf("Result:\n"); printf("%d,%f\n",a,b); printf("%d,%f\n",*p,*q); printf("The Address of a,b:%p,%p\n",&a,&b); printf("The Address of a,b:%p,%p\n",p,q); p=&c; printf("c=%d\n",*p); printf("The Adress of c:%x,%x\n",p,&c); }
#include <stdio.h> void swap1(int x,int y); void swap2(int *x,int *y); int main() { int a,b; printf("Please Input a=:"); scanf("%d",&a); printf("\nb=:"); scanf("%d",&b); swap1(a,b); printf("\nAfter Call swap1:a=%d b=%d\n",a,b); swap2(&a,&b); /*实参传递*/ printf("\nAfter Call swap2:a=%d b=%d\n",a,b); return 0; } void swap1(int x,int y) { int temp; temp=x; x=y; y=temp; } void swap2(int *x,int *y) { int temp; temp=*x; *x=*y; *y=temp; /*交换x,y地址上的值*/ }
#include<stdio.h> char *reverse(char *str); char *link(char *str1, char *str2); main() { char str[30], str1[30], *str2; printf("input reversing character string:"); gets(str); str2=reverse(str); printf("\noutput reversed character string:"); puts(str); printf("input string1:"); gets(str); printf("input string2:"); gets(str1); str2=link(str,str1); puts(str2); return 0; } char *reverse(char *str) { char *p,*q,temp; p=str, q=str; while(*p !=‘\0‘) //判断是否是最后一个数值 p++; p--; while(q<p) { temp=*q; *q=*p; *p=temp; p--; //指针做相向移动处理 q++; } return str; } char *link(char *str1, char *str2) { char *p=str1, *q=str2; while(*p !=‘\0‘) p++; while(*q !=‘\0‘) { *p=*q; p++; q++; } str2=NULL; //令结束字符为空字符 return str1; }
#include <stdio.h> #define N 10 void arrsort(int a[],int n); main() { int a[N],i; for(i=0;i<N;i++) scanf("%d",&a[i]); arrsort(a,N); for(i=0;i<N;i++) printf("%d ",a[i]); } void arrsort(int a[],int n) { int *p,*q,temp; p=a; q=a+n-1; while(p<q){ while(*p%2!=0) p++; while(*q%2==0) q--; if(p>q) break; temp=*p; *p=*q; *q=temp; p++; q--; } }