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

上一篇: C语言指针 下一篇: C语言指针算术运算