程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> 對指針的理解,指針理解

對指針的理解,指針理解

編輯:關於C語言

對指針的理解,指針理解


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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved