Difference between malloc() and calloc() function

Explain the difference between malloc() and calloc() function.

Both functions are used to dynamically allocate the memory. The difference is that calloc initializes the allocated memory to 0 or Null while malloc contains garbage values.

The following are the differences between malloc() and calloc():

- Byte of memory is allocated by malloc(), whereas block of memory is allocated by calloc().

- malloc() takes a single argument, the size of memory, where as calloc takes two parameters, the number of variables to allocate memory and size of bytes of a single variable

- Memory initialization is not performed by malloc() , whereas memory is initialized by calloc().

- malloc(s) returns a pointer with enough storage with s bytes, where as calloc(n,s) returns a pointer with enough contiguous storage each with s bytes.
Difference between strcpy() and memcpy() function
strncpy() is similar to memcopy() in which the programmer specifies n bytes that need to be copied.....
Difference between exit() and _exit() function
exit() and _exit() : exit() does cleanup work like closing file descriptor, file stream and so on, while _exit() does not....
Compare array with pointer
The first declaration allocates memory for a pointer; the second allocates memory for 20 characters.....
Post your comment
Discussion Board
@Vidya Sagar
Nice job
Niteen Dhule 08-30-2015