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:
- double pi = 3.14 + 0.0016;
However, Initialization is illegal:
- 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.