c / c ++ memory allocation

DESCRIPTION allocated using sample code 

 

/ * 
 * Stack area (Stack): 
 * the parameter values for function, local variables, etc. 
 * automatically allocated by the compiler and releasing 
 * operate similarly to a stack data structure 
 * heap (heap): 
 * by the general programmers allocation and release, if the programmer does not release, may be provided by the operating system at the end of the recovery program 
 * distribution similar to the list 
 * Note that the data structure in the heap are two different things 
 * global area (static area) (static): 
 * global variables and static variables are stored together in 
 * initialize global variables and static variables in an area, uninitialized global variables and uninitialized static variables in an area adjacent to another 
 release by the system after the end of the program * 
 * text constant regions: 
 * constant string is placed here 
 * released by the end of the program system 
 * program code area: 
 * storing body function binary code 
* / 

#include <stdlib.h> #include <stdio.h> #include < string .h> int A = 0; // global initialization region char * P1; // global zone uninitialized int main () { int B; // stack char S [] = " ABC " ; // stack char * P2; // stack, const char * P3 = " 123456 " ; // 123456 in the constant region, p3 on the stack static int C = 0 ; // global (static) zone initialize P1 = ( char *) the malloc ( 10 ); //10-byte stack area allocated region P2 = ( char *) the malloc ( 20 is ); // 20 is byte area assigned heap region strcpy (P1, " 123456 " ); // 123456 in the constant region, compiled optimization may point to the same position p3 }

 

Guess you like

Origin www.cnblogs.com/etangyushan/p/11204912.html