在C語言中指針的指針概念中,指針指向另一個指針的地址。
在C語言中,指針可以指向另一個指針的地址。我們通過下面給出的圖來理解它:
我們來看看指向指針的指針的語法 -
int **p2;
下面來看看一個例子,演示如何將一個指針指向另一個指針的地址。參考下圖所示 -
如上圖所示,p2
包含p
的地址(fff2)
,p
包含數(shù)字變量的地址(fff4)
。
下面創(chuàng)建一個源代碼: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);
}
執(zhí)行上面示例代碼,得到以下結(jié)果 -
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