Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )
Article Directory
malloc、realloc、calloc、free by C
- Be sure to determine whether the successful application of space
calloc
After the success of the application memory is initialized to 0.malloc
,realloc
Does not initialize memory after the application is successful.- After the dynamic memory allocation must
free
free up space.
void *__cdecl malloc(size_t _Size);
void *__cdecl calloc(size_t _Count, size_t _Size);
void *__cdecl realloc(void *_Block, size_t _Size);
char *ptr;
ptr = (char *)malloc(sizeof(char) * ArrLng);
ptr = (char *)calloc(ArrLng, sizeof(char));
ptr = (char *)realloc(ptr, sizeof(char) * ArrLng);
free(ptr);
Heap head
stack stack
new、delete by C++