Memory Allocation
malloc
- Allocates a single block of memory. Initialized to garbage values. Returns a pointer to the first byte of the allocated memory that can be casted into any type.
ptr = (cast-type*) malloc(byte-size)
calloc
- Allocates memory in the heap and initializes the memory to zero.
ptr = (cast-type*) calloc(n, element-size);
free
- Deallocates memory.
free(ptr);
realloc
- Reallocates memory, and the old content will be copied to the new memory area.
ptr = realloc(ptr, newSize);