The memory used by a program compiled by C + + is divided into the following sections
1, stack area (stack)-by the compiler automatically assigned to release, hold the function of the parameter name, the name of the local variable. The operation is similar to the stack in the data structure.
2, heap area (heap)-assigned by the programmer to release, if the programmer does not release, the program at the end may be reclaimed by the OS. Note that it is different from the heap in the data structure, and the distribution is similar to the linked list.
3, Global zone (static area) (static)-the storage of global variables and static variables is placed in a piece, the initialization of global and static variables in a region, uninitialized global variables and uninitialized static variables in another adjacent area. The system is released after the program is finished.
4, literal constant area-a constant string is placed here, after the program is released by the system.
5, program code area-the binary code that holds the function body.
Copy Code code as follows:
int a = 0;//Global initialization area
char*p1;//Global Uninitialized Zone
Main ()
{
intb;//Stack
chars[] = "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 area
P1 = (char*) malloc (10);
P2 = (char*) malloc (20);/The allocated 10 and 20 bytes of area are in the heap area.
}
strcpy (P1, "123456"); 123456\0 is placed in a constant area, and the compiler may optimize it with the "123456" that the P3 points to as a place.