- //用指针将数组a中n个整数按相反顺序存放
- #include <stdio.h>
- int main(){
- int a[] = {1,2,3,4,5,6,7,8,9,10};
- int *p = a;
- int len = sizeof(a)/sizeof(int);
- int i = 0;
- printf("%d\n",len);
- while(i<len/2){
- int temp;
- temp = *(p+i);
- *(p+i) = *(p+(len-1-i));
- *(p+(len-1-i)) = temp;
- //a[i] = *(p+(len-i-1));
- //printf("%d\t",a[i]);
- i++;
- }
- for(i=0;i<len;i++){
- printf("%d\t",a[i]);
- }
- return 0;
- }
复制代码
|
|