首页 > 其他 > 详细

对指针的理解

时间:2015-02-10 11:06:08      阅读:255      评论:0      收藏:0      [点我收藏+]

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

对指针的理解

原文:http://www.cnblogs.com/brave-firm/p/4283229.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!