1、定义指针及指针的指针
int a = 10;
int *p = &a;
int **p2 = &p;
printf("a :%d\n",a);
printf("*p :%d\n",*p);
printf("p2 :%x\n",p2);//p的地址
printf("*p2 :%x\n",*p2);//p2指向的指针p指向的变量的地址
printf("p :%x\n",p);
printf("**p2:%d\n",**p2);//p2指向的指针p指向的变量的值
2、指针和const的关系
2.1、只读指针变量
int a = 10;
int b = 20;
int *const p = &a;
*p = 11;//运行成功
p = &b;//编译报错(*const表示固定了地址)
printf("%d", *p);//输出11
2.2、指向只读变量的指针
int a = 10;
int b = 20;
//指向只读变量的指针
int const *p2 = &a;
p2 = &b;
*p2 = 21;//编译报错
2.3、指向只读变量的只读指针
int a = 10;
int b = 20;
int const *const p3 = &a;
p3 = &b;
*p3 = 12;