December 04, 2017

Difference between "memset" and "malloc"

❑ memset
❍ #include <memory.h> or <string.h>
❍ void *memset(void *addr, int val, size_t len); : This writes "val" as much as "len" Bytes in the memory pointed to by "addr". "addr" is returned.
❍ It is possible to write values to memory but memory allocation is not possible.

❑ malloc
❍ #include <stdlib.h> or <malloc.h>
❍ void *malloc(size_t size); : It allocates as much memory as "size" Bytes and returns the first address of the allocated memory.
❍ It is possible to allocate memory but writing values to memory is not possible.