<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # C - 指向指針的指針(雙重指針) > 原文: [https://beginnersbook.com/2014/01/c-pointer-to-pointer/](https://beginnersbook.com/2014/01/c-pointer-to-pointer/) 我們已經知道指針保存了同一類型的另一個變量的地址。當指針保存另一個指針的地址時,這種類型的指針稱為**指針的指針**或**雙重指針**。在本指南中,我們將學習什么是雙重指針,如何聲明它們以及如何在 C 編程中使用它們。要理解這個概念,你應該知道[指針](https://beginnersbook.com/2014/01/c-pointers/)的基礎知識。 ## 如何在 C 中聲明指針的指針(雙重指針)? ```c int **pr; ``` 這里`pr`是一個雙重指針。在雙重指針的聲明中必須有兩個`*`。 讓我們借助圖表來理解雙重指針的概念: ![pointer-to-pointer or double pointer](https://img.kancloud.cn/df/51/df513c3903b7807bb35ba1bb0fd673b0_500x300.jpg) 根據圖表,`pr2`是一個普通指針,它保存整數變量`num`的地址。圖中還有另一個指針`pr1`,它保存另一個指針`pr2`的地址,這里的指針`pr1`是一個指向指針的指針(或雙重指針)。 **上圖中的數值:** ```c Variable num has address: XX771230 Address of Pointer pr1 is: XX661111 Address of Pointer pr2 is: 66X123X1 ``` ## 雙重指針示例 讓我們根據上面看到的圖表編寫一個 C 程序。 ```c #include <stdio.h> int main() { int num=123; //A normal pointer pr2 int *pr2; //This pointer pr2 is a double pointer int **pr1; /* Assigning the address of variable num to the * pointer pr2 */ pr2 = # /* Assigning the address of pointer pr2 to the * pointer-to-pointer pr1 */ pr1 = &pr2; /* Possible ways to find value of variable num*/ printf("\n Value of num is: %d", num); printf("\n Value of num using pr2 is: %d", *pr2); printf("\n Value of num using pr1 is: %d", **pr1); /*Possible ways to find address of num*/ printf("\n Address of num is: %p", &num); printf("\n Address of num using pr2 is: %p", pr2); printf("\n Address of num using pr1 is: %p", *pr1); /*Find value of pointer*/ printf("\n Value of Pointer pr2 is: %p", pr2); printf("\n Value of Pointer pr2 using pr1 is: %p", *pr1); /*Ways to find address of pointer*/ printf("\n Address of Pointer pr2 is:%p",&pr2); printf("\n Address of Pointer pr2 using pr1 is:%p",pr1); /*Double pointer value and address*/ printf("\n Value of Pointer pr1 is:%p",pr1); printf("\n Address of Pointer pr1 is:%p",&pr1); return 0; } ``` **輸出:** ```c Value of num is: 123 Value of num using pr2 is: 123 Value of num using pr1 is: 123 Address of num is: XX771230 Address of num using pr2 is: XX771230 Address of num using pr1 is: XX771230 Value of Pointer pr2 is: XX771230 Value of Pointer pr2 using pr1 is: XX771230 Address of Pointer pr2 is: 66X123X1 Address of Pointer pr2 using pr1 is: 66X123X1 Value of Pointer pr1 is: ?66X123X1 Address of Pointer pr1 is:?XX661111 ``` > 關于此程序的輸出存在一些混淆,當您運行此程序時,您將看到類似于此的地址:`0x7fff54da7c58`。我以不同格式提供地址的原因,是我希望您將此程序與上圖相關聯。我已經使用了上圖中的確切地址值,因此您可以輕松地將此程序的輸出與上圖相關聯。 您還可以使用以下簡單公式了解程序邏輯: ```c num == *pr2 == **pr1 &num == pr2 == *pr1 &pr2 == pr1 ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看