C语言教程:指向另一个指针地址的指针

2023年 7月 14日 34.1k 0

C语言中指针的指针概念中,指针指向另一个指针的地址。

在C语言中,指针可以指向另一个指针的地址。我们通过下面给出的图来理解它:

C语言教程:指向另一个指针地址的指针

我们来看看指向指针的指针的语法 -

int **p2;

C

指针的指针的示例

下面来看看一个例子,演示如何将一个指针指向另一个指针的地址。参考下图所示 -

C语言教程:指向另一个指针地址的指针

如上图所示,p2包含p的地址(fff2)p包含数字变量的地址(fff4)

下面创建一个源代码:pointer-to-pointer.c,其代码如下所示 -

#include         
#include       
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);

}

C

执行上面示例代码,得到以下结果 -

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

相关文章

JavaScript2024新功能:Object.groupBy、正则表达式v标志
PHP trim 函数对多字节字符的使用和限制
新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
为React 19做准备:WordPress 6.6用户指南
如何删除WordPress中的所有评论

发布评论