码迷,mamicode.com
首页 > 其他好文 > 详细

对指针的理解

时间:2015-02-10 11:09:12      阅读:184      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!