Constant in C ++: the constant of the define constant Const.

Source: Internet
Author: User

In C ++, constants are constants, such as int A = 5 and 5. So where does a constant exist? Is memory used?

# Include <iostream. h>

Int;
Main (void)
{
A = 10;
Cout <A <Endl;
Cout <& A <Endl;
 
Cout <& 10 <Endl; // invalid

Return 0;
}

The preceding section is from vc6.0.Code: The following message is displayed during compilation: Error c2101: '&' on constant. That is, you cannot use the address operator for constants. This constant is 10 inProgramIn what form does the running process exist? How does one complete the assignment operation? If you have learned the assembly language, you may be familiar with the following command:

MoV ax, #5 the specific format is not clearly remembered, it is to move the value to the Register ax 5. in this case, 5 exists in the Code zone in the form of immediate number: embedded into the command. When the command is executed, the format of the preceding command is assigned to global or local variables. This operation does not need to be written into the stack, so it will not exist in the data storage area in the form of data: heap, stack, static data zone. And also embedded

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.