首頁  >  文章  >  後端開發  >  雙指標(指向指標)在C語言中

雙指標(指向指標)在C語言中

WBOY
WBOY轉載
2023-09-10 12:09:03533瀏覽

雙指標(指向指標)在C語言中

指標用於儲存變數的位址。因此,當我們定義一個指標到指標時,第一個指標用於儲存第二個指標的位址。因此它被稱為雙指標。

演算法

Begin
   Declare v of the integer datatype.
      Initialize v = 76.
   Declare a pointer p1 of the integer datatype.
   Declare another double pointer p2 of the integer datatype.
   Initialize p1 as the pointer to variable v.
   Initialize p2 as the pointer to variable p1.
   Print “Value of v”.
      Print the value of variable v.
   Print “Value of v using single pointer”.
      Print the value of pointer p1.
   Print “Value of v using double pointer”.
      Print the value of double pointer p2.
End.

一個理解雙指標的簡單程式:

#範例

int main() {
   int v = 76;
   int *p1;
   int **p2;
   p1 = &v;
   p2 = &p1;
   printf("Value of v = %d\n", v);
   printf("Value of v using single pointer = %d\n", *p1 );
   printf("Value of v using double pointer = %d\n", **p2);
   return 0;
}

輸出

Value of v = 76
Value of v using single pointer = 76
Value of v using double pointer = 76

以上是雙指標(指向指標)在C語言中的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除