The role of the const

Source: Internet
Author: User

The function of const is to declare a read-only property.

The const function differs in different positions, but still plays a read-only attribute.

int const A;

const int A;

The function is the same, which defines a constant integer type. A is allocated in the static storage area.

const int *a;

int const *A;

The variable to which a is directed cannot be modified.

int b;

int * Const a=&b;

A is read-only and cannot operate on a, that is, a++ is wrong. However, you can modify the variables indicated by a, which must indicate the direction of a at initialization, because you cannot modify the direction of a at a later time.

const INT * Const a=&b;

A is read-only, initialized at the time of declaration, and cannot modify the variable it points to by a, i.e. *a=9;

The role of the 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: 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.