C語言指針的指針

在C語言中指針的指針概念中,指針指向另一個指針的地址。

在C語言中,指針可以指向另一個指針的地址。我們通過下面給出的圖來理解它:

C語言指針的指針

我們來看看指向指針的指針的語法 -

int **p2;

指針的指針的示例

下面來看看一個例子,演示如何將一個指針指向另一個指針的地址。參考下圖所示 -

C語言指針的指針

如上圖所示,p2包含p的地址(fff2)p包含數字變量的地址(fff4)

下面創建一個源代碼:pointer-to-pointer.c,其代碼如下所示 -

#include <stdio.h>        
#include <conio.h>      
void main() {
    int number = 50;
    int *p;//pointer to int  
    int **p2;//pointer to pointer      

    p = &number;//stores the address of number variable    
    p2 = &p;

    printf("Address of number variable is %x \n", &number);
    printf("Address of p variable is %x \n", p);
    printf("Value of *p variable is %d \n", *p);
    printf("Address of p2 variable is %x \n", p2);
    printf("Value of **p2 variable is %d \n", **p2);

}

執行上面示例代碼,得到以下結果 -

Address of number variable is 3ff990
Address of p variable is 3ff990
Value of *p variable is 50
Address of p2 variable is 3ff984
Value of **p2 variable is 50