欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

指针与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赋值。