The difference between const int *, int * const, int const *

Source: Internet
Author: User

Some people May is confused about the sequence of a const and * on declaration in c++/c, me too.

Now I think we can distinguish them by the this to:

  1.only noticing the position of const to *, and we can find, the following statements is same:

Const int * foo_int; int  Const * FOO_INT_; Same.

2.regarding const as a postpositive attributes, andYou'llknow the content whic H is Const.

  

intFoo =6;intFoo_ =7;//the Foo_int is const and 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 are const, but Foo_int_ can be chaged.int*ConstFoo_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 *

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.