c 语言,指针,指针的指针
指针就是指向变量地址的东西。
比如:
- 定义了一个 int 变量
p
,值为 1 。 - 定义了 int 指针
pInt
指向了变量p
, 它的名字前面有个*
,此时pInt
就是 p 的地址,当前面加上*
就代表它指向的原变量p
,也就是说*pInt
的值就是p
的值。
同理,指向指针的指针就是多了一层,有两个**
,如下。
这里面 &
单目运算符就是取变量地址的,所以能看到下面的 int *pInt = &p
。
当指针前面加上对应它的 *
的时候就代指的原变量。
**pPint <=> *pInt <=> p
代码
#include "stdio.h"int main(){int p = 1;int *pInt = &p;int **pPInt = &pInt;printf("number p is %d, pointer *pInt is %d, pointerPointer **pPInt is %d", p, *pInt,**pPInt);
}