#include <stdio.h>
int main() {
// (1)指向整型常量的指针。【const pointer】 地址:可变,值:不可变
const int *p1; // 等价于 int const *p2;
printf("[[constant pointer]] before change address: %p\n", p1);
int a = 1;
p1 = &a;
printf("[[constant pointer]] after change address: %p\n\n", p1);
// (2)指向整型常量的指针。【pointer to const】 地址:不可变,值:可变
int b = 120;
int *const p3 = &b;
printf("[[pointer to const]] before change value: %d\n", *p3);
*p3 = 123;
printf("[[pointer to const]] after change value: %d\n\n", *p3);
// (3)指向整型常量的常量指针。【const pointer to a const】 地址:不可变,值:不可变
const int *const p4; // 等价于 int const *const p5;
printf("[[constant pointer to a constant]]: NEITHER CAN CHANGE [addr] NOR [value]");
return 0;
}
[[constant pointer]] before change address: 0000000000000000
[[constant pointer]] after change address: 00000025175ff98c
[[pointer to const]] before change value: 120
[[pointer to const]] after change value: 123
[[constant pointer to a constant]]: NEITHER CAN CHANGE [addr] NOR [value]
Process finished with exit code 0
标签:const,常量,int,value,C语言,关于,constant,pointer,change
From: https://www.cnblogs.com/cloucodeforfun/p/18166510