Expands or contracts the existing area pointed to by ptr, copying to new location
If fails, returns null
1
void*realloc(void*ptr,size_tsize)
memcpy
1
2
void*memcpy(void*dest,constvoid*source,size_tnum)// copies the values of num bytes from a source to dest
memset
1
2
void*memset(void*ptr,intval,size_tnum)// sets the first num bytes in memory to be val
calloc
1
2
3
4
5
6
7
void*calloc(intnum_of_items,intsize)// allocates num_of_items objects of the specified size
// in the memory and sets the memory to 0
// essentially equivalent to
void*ptr=malloc(num_of_items*size);memset(ptr,0,num_of_items*size);
Syntax
1
2
3
4
5
6
7
(void*)malloc(size_t)// allocates size_t consecutive bytes in memory
// size_t alias for unsigned integer type
// ======= Usage =======
int*array=(int*)malloc(n*sizeof(int));