指针遍历数组
1 #include<stdio.h> 2 3 int main() 4 { 5 int arr[]={1,5,6,3,85,62,20,98}; 6 int len=sizeof(arr)/sizeof(arr[2]); 7 int i,*p=arr; 8 /*for (i=0;i<len;i ++) { 9 printf("%d ",*(arr+i)); 10 }*/ 11 printf("%p %X\n",&arr,p); 12 for (i=0;i<len;i++){ 13 printf("%d ",*p++);//借助自增运算符来遍历数组元素 14 printf("%X\n",p); 15 } 16 /*printf("%p %X \n",&arr,p);*/ 17 18 char b[]="hello"; 19 printf("%s\n",b); 20 len=sizeof(b)/sizeof(b[6]); 21 for (int n=0;n<len;n++) { 22 printf("%c ",b[n]); 23 printf("%c\n",*(b+n)); 24 } 25 return 0; 26 }
本文来自博客园,作者:泥烟,CSDN同名, 转载请注明原文链接:https://www.cnblogs.com/Knight02/p/13976696.html