#include <stdio.h>
int main () {
int urn[5] = {100,200,300,400,500};
int *ptr1, *ptr2, *ptr3;
ptr1 = urn; //直接把数组地址给指针ptr1
ptr2 = &urn[2]; //把数组第三个数值的地址给指针ptr2;
printf("urn adress is : %p\n", urn);
printf("ptr1 = %p, *ptr1 = %d ,&ptr1 = %p\n",
ptr1, *ptr1, &ptr1); // 要注意指针指向的地址, 指针指向的地址的值, 指针的地址 之间的区别;
ptr3 = ptr1 + 4;
printf("adding an int to pointer:\n");
printf("ptr3 = %d", *ptr3);
ptr1++;
printf("value after ptr1++\n");
printf("ptr1 = %p, *ptr1 = %d ,&ptr1 = %p\n",
ptr1, *ptr1, &ptr1);
ptr2--;
printf("value after ptr2--\n");
printf("ptr2 = %p, *ptr2 = %d ,&ptr2 = %p\n",
ptr2, *ptr2, &ptr2);
--ptr1;//ptr1恢复为初始值;
++ptr2;//ptr2恢复为初始值;
printf("substracting on pointer from another: \n");
printf("ptr2 = %p, ptr1 = %p ; ptr2-ptr1 = %d\n",
ptr2, ptr1, ptr2-ptr1); //指针指向地址的值的地址的减法;
printf("substring an int from a pointer : \n");
printf("ptr3 = %p, ptr3-2 = %p ,*(ptr3-2) = %d\n",
ptr3, ptr3-2, *(ptr3-2));
return 0;
}