首页 > 代码库 > the difference between const int *, int * const, int const *
the difference between const int *, int * const, int const *
Some people may be confused about the sequence of const and * on declaration in C++/C, me too.
Now I think we can distinguish them by this way:
1.only noticing the position of const to *, and we can find that the following statements are same:
const int * foo_int; int const * foo_int_; //same.
2.regarding const as a postpositive attributes,and you will know the content which is const.
int foo = 6; int foo_ = 7; //the foo_int is const, but the pointer to foo_int can be chaged. int const * foo_int = &foo; //illegal, the value cannot be chaged //*foo_int = 7 //okay! foo_int = &foo_; //the pointer to int is const, but foo_int_ can be chaged. int * const foo_int_ = &foo_int; //illegal, the pointer cannot be changed. //foo_int = &foo_int_; //even if the new pointer is same, it‘s illegal //foo_int = &foo_int; //okay *foo_int = 8;
the difference between const int *, int * const, int const *
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。