Read it backwards (as driven by Clockwise/Spiral Rule):
int* - pointer to int int const * - pointer to const int int * const - const pointer to int int const * const - const pointer to const int Now the first const can be on either side of the type so:
const int == int const const int const == int const const If you want to go really crazy you can do things like this:
int ** - pointer to pointer to int int ** const - a const pointer to a pointer to an int int const - a pointer to a const pointer to an int int const ** - a pointer to a pointer to a const int int const const - a const pointer to a const pointer to an int
发布评论
评论(3)
在阅读和const相关的指针时,可以记一下这个规则:
左数右指
。意思是:当const出现在
*
号左侧时,指针指向的数据不可改变;当const出现在*
号右侧时,指针指向不可改变(不可改变的意思是不能通过当前指针直接进行改变)。stackoverflow上有一模一样的问题,我就复制粘贴了