Adobe Interview Question
Software Engineer / DevelopersThere is one more difference which very few people know which is - Calloc returns the contiguous block of memory allocated on heap whereas for Malloc it is not the case.
-- Difference between malloc and calloc
-- Signatures are different
-- Malloc(s);
-- Allocates byte of memory
-- Returns a pointer for enough storage for an object of s bytes
-- Calloc(n,s);
-- Allocates block of memory
-- Returns a pointer for enough contiguous storage for n objects, each of s bytes
-- The storage is all initialized to zeros
-- Calloc(m, n) is essentially equivalent to
p = malloc(m * n);
memset(p, 0, m * n);
calloc initializes memory allocated with 0 bytes but malloc does not
- gumber July 31, 2009