The memory used by a program compiled by C + + is divided into the following sections
1, Stack: The compiler automatically allocates the release, the value of the stored function, the value of the local variable, and so on. It operates in a manner similar to a stack in a data structure.
2, heap area (heap): Generally by the programmer assigned to release, if the programmer does not release, the end of the program may be recycled by the OS. Note that it is not the same as the heap in the data structure, the distribution is similar to the list, hehe.
3. Global zone (Static): The storage of global variables and static variables is placed in a block, initialized global variables and static variables in an area, uninitialized global variables and uninitialized static variables in another area adjacent. -System release after the program is finished
4, the literal constant area: the constant string is put here. Released by the system after the program is finished
5, program code area: the binary code that holds the function body.
Add: Global zone (static area) and literal constant area collectively referred to as data area
Constants: Simple constants, some systems may be treated as "immediate number", exist in the code area, string, struct constant, just like static variables, stored in the data area.
Main considerations for operating system core code: Code area, heap area
Compiler main considerations: Stack area, data area
The _alloca function allocates memory in the stack.
Example Program:
It was written by a predecessor, very detailed
Main.cpp
int a = 0; Global initialization Zone
Char *p1; Global uninitialized Zone 
Main ()  
{ Span class= "Apple-converted-space" > 
int b; stack  
Char s[ ] = "ABC"; Stack  
char *p2; stack  
Char *p3 = "123456"; 123456\0 in the constant area, p3 on the stack.  
static int c = 0; global (static) initialization zone
P1 = (char *) malloc (
P2 = (char *) malloc (
The area allocated 10 and 20 bytes is in the heap area.  
strcpy (P1, "123456"), 123456\0 is placed in the constant area, and the compiler may associate it with the "123456" that P3 points to Optimized into one place.  
} 
Class of memory used by programs compiled by C + + +