Storage of const variables and define

Source: Internet
Author: User

The read-only variables defined by const only provide the corresponding memory address from the Assembly perspective, rather than the immediate number as defined by define. Therefore, the read-only variables defined by const areProgramThere is only one copy during the running process (because it is a global read-only variable stored in the static zone) the macro variables defined by define have several copies in the memory. The define macro is replaced during the pre-compilation phase, while the read-only variables modified by const are determined that the value of define macro has no type during compilation. read-Only variables modified by const have specific types.

 

In the generated execution program:

Define occupiesCodeSegment space and pre-processing time while const occupies global storage space

 

The read-only variable modified by const cannot be used as the dimension of the defined array, nor can it be placed behind the case keyword.

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.