指针与const
程序员文章站
2022-06-23 14:33:03
int i; const int* p1=&i; int const* p2=&i; int *const p3=&i; 判断哪个被const了的标志是const在*的前面还是后面 p1、p2是同一种const,不能直接对*p赋值;p3不能进行p3++操作。 如:const int* p=&i; i ......
int i;
const int* p1=&i;
int const* p2=&i;
int *const p3=&i;
判断哪个被const了的标志是const在*的前面还是后面
p1、p2是同一种const,不能直接对*p赋值;p3不能进行p3++操作。
如:const int* p=&i;
i=26;//OK
p=&j;//OK
*p=26;//出错,*在const后,不能直接对*p赋值。