#include <stdio.h> #include <stdlib.h> #define N 6 int main() { int nums[N]={20,25,30,35,40,45}; int *ptr_nums=nums; int i; int *ptr_nums1=&nums[0]; int *ptr_nums2=&nums[N-1]; int temp; for(i=0;i<N;i++) { printf("%d\t",*(ptr_nums+i)); } printf("%p\n",&ptr_nums);//数组名是数组的首元素地址 for(i=0;i<N/2;i++) { temp=nums[i]; nums[i]=nums[N-i-1]; nums[N-i-1]=temp; } for(i=0;i<N;i++) { printf("%d\t",nums[i]); } //最后指针全部指向了别的内存地址 用完之后记得重新指向新的地址或者置NULL *ptr_nums1=NULL; *ptr_nums2=NULL; return 0; }
原文:https://www.cnblogs.com/hw1988/p/10554213.html