对指针的理解

int main(void)

{

  int a;

  int *p;
  int **p1;
  a = 5;
  p = &a;
  p1 = &p;
 
  printf("\n");
  printf("the address of a is %p\n", &a);
  printf("the value of p is %p and the adress of p is %p\n", p, &p);
  printf("the value of p1 is %p and the address of p1 is %p\n",p1, &p1);
 
  printf("\n\n");
 
  printf("a's value is %d\n", a);
  printf("a's value is %d access by first pointer\n", *p);
  printf("a's value is %d access by second pointer\n",*(*p1));
 
  printf("\n");
}

输出结果如下:
the address of a is 0x7fffd57a181c
the value of p is 0x7fffd57a181c and the adress of p is 0x7fffd57a1808
the value of p1 is 0x7fffd57a1808 and the address of p1 is 0x7fffd57a1810
 
 
a's value is 5
a's value is 5 access by first pointer
a's value is 5 access by second pointer


解析:
p = &a;
p = 变量 a的地址 = 0x7fffd57a181c
*p = a的值 = 5  //一级指针

p1 = &p;
p1 = 变量p的地址
*p1 = 变量p的值=a变量的地址
*(*p1) = *(变量p的值)=*(变量a的地址)=5
posted on 2015-02-10 10:42  一个大菜B  阅读(310)  评论(0编辑  收藏  举报