Basic concepts of C ++ storage areas

Source: Internet
Author: User

The application of the C ++ programming language enables developers to easily complete the functional requirements required in various program development, greatly improving programming efficiency. In this article, we will explain in detail the basic concepts of C ++ storage areas, so as to further interpret this language.

  • A Brief Introduction to the C ++ Operating Mechanism
  • Basic concepts of C ++ cyclic statements
  • Application Methods for C ++ class members
  • How to use C ++ to call the C-Linked Library
  • Summary of C ++ typedef usage

In program development, we divide the C ++ storage area into the following steps:

1. stack)-the compiler automatically allocates the release, stores the function parameter values, local variable values, and so on. The operation method is similar to the stack in the data structure.

2. heap in the heap area)-generally, it is assigned and released by the programmer. If the programmer does not release the heap, the program may be recycled by the system at the end. Note that it is different from the heap in the data structure. The allocation method is similar to the linked list.

3. The Global static zone) is static. global variables and static variables are stored in one partition. initialized global variables and static variables are stored in one partition, uninitialized global variables and uninitialized static variables are in another adjacent area. The program is released by the System

4. Text Constant Area-constant strings are placed here. The program is released by the System

5. program code area-stores the binary code of the function body.

Local variables in the C ++ storage area can be initialized using any expressions with consistent types.

The global variable can only be initialized using the Constant Expression.

For example, the initialization of the global variable pi is legal:

 
 
  1. double pi = 3.14 + 0.0016;  

However, Initialization is illegal:

 
 
  1. double pi = acos(-1.0);  

If the global variable is not initialized during definition, the initial value is 0. If the local variable is not initialized during definition, the initial value is uncertain.

Therefore, the local variables in the C ++ storage area must be assigned a value before they are used. If you perform subsequent calculations based on an uncertain value, a Bug will certainly be introduced.

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.