一、关于指向const的指针
const int **p1;
int *p2;
p1 = &p2; // error 非const地址无法赋值给const 指针
const int temp_1 = 4;
int temp_2 = 9;
const int *pt_1;
int *pt_2;
pt_1 = &temp_1;
pt_2 = &temp_1;//error const数据地址无法赋值给非const指针, 防止通过非const指针修改const数据
pt_1 = &temp_2;
pt_1 = &temp_1;
总结:
1.const指针可以指向const和非const数据。
2.非const指针不可以指向consts数据。
核心思想:防止const 数据被通过指针被间接修改。