顶层const和底层const
int i = 10; const int* p1 = &i;//这里是底层的const,能改变p1,但是不能改变*p1 //*p1 = 200 错误 p1 = &i//正确 int* const p2 = &i;//顶层const,能改变*p2,但不能改变p2 *p2 = 200; p2 = &i//错误
分享文章:顶层const和底层const
分享URL:http://scjbc.cn/article/pphhsd.html
int i = 10; const int* p1 = &i;//这里是底层的const,能改变p1,但是不能改变*p1 //*p1 = 200 错误 p1 = &i//正确 int* const p2 = &i;//顶层const,能改变*p2,但不能改变p2 *p2 = 200; p2 = &i//错误