C语言指针的指针
作者:--
发布时间:2019-11-20
评论:0
阅读:0
在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