The function
void* malloc(size_t size)
is used to allocate
size
number of bytes.
It returns a pointer to the allocated block.
The function
void* calloc(size_t nelement, size_t elementSize)
allocates enough memory to store a total of
nelement
elements of size
elementSize
. You'd use this to allocate a known number of elements, such as allocating 10
my_struct
s:
struct my_struct
{
int x;
int y;
}
...
my_struct* = calloc(10, sizeof(my_struct);
It's explained in more detail
here[
^]
The memory is also initialized when using
calloc
.
Hope this helps,
Fredrik