C語言指標的指標


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

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

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

int **p2;

指標的指標的範例

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

如上圖所示,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