1 in a manner to traverse the pointer array elements
int ARR [] = { . 11 , 22 is , 33 is , 44 is , 55 }; int len = the sizeof (ARR) / the sizeof ( int ); // find the array length char I; for (I = 0 ; I <len; I ++ ) { the printf ( " % D " , * (ARR + I)); // * (ARR + I) is equivalent to ARR [I] }
is of type int * arr, when each addition. 1, arr own value (address) will increase sizeof (int).
2 array element pointers way to iterate
int arr[]={11. 22, 33, 44, 55 }; int len = sizeof(arr)/sizeof(int), *p=&arr; //等价于*p=&arr[0] char i; for(i=0; i<len; i++) { printf("%d ", *(p+i)); //*(p+i)等价于*(arr+i) }
p, arr, & arr [0] is equivalent to
*(p+i)、*(arr+i)、arr[i]、p[i ]等价
3 by means of increment operator through the array elements
Whether the name is an array or array pointer, you can use the above two ways to access the array elements, except that: an array name is a constant, his value can not be changed; array pointer is a variable (unless otherwise stated it is a constant), its value can be changed. In other words, the array name can only point to the beginning of the array, and an array of pointers can point to the beginning of the first array, and then point to other elements.
int ARR [] = { . 11 . 22 is , 33 is , 44 is , 55 }; int len = the sizeof (ARR) / the sizeof ( int ), * P = & ARR; // equivalent to * P = & ARR [0] char I; for (I = 0 ; I <len; I ++ ) { the printf ( " % D " , * P ++); // * ++ equivalent to P * (P ++) }
* P ++ can not be changed * arr ++, because arr is constant, while arr ++ will change its value.
int *p=&arr[2]