首頁 > 後端開發 > C++ > 主體

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

WBOY
發布: 2023-09-10 12:09:03
轉載
545 人瀏覽過

雙指標(指向指標)在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
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!