Best Answer

malloc returns a block of memory that is allocated for the programmer to use, but is uninitialized. The memory is usually initialized by hand if necessary -- either via the memsetfunction, or by one or more assignment statements that dereference the pointer. An alternative is to use the calloc function, which allocates memory and then initializes it. The malloc and calloc differs in the number of arguments. The malloc allocates memory of given size but the calloc can allocates array of memory locations of given size.

User Avatar

Wiki User

โˆ™ 2009-02-26 10:34:53
This answer is:
User Avatar
Study guides

Data Science

See all cards
7 Reviews

Add your answer:

Earn +20 pts
Q: What are the differences between malloc and calloc?
Write your answer...
Still have questions?
magnify glass
Related questions

Which of libraries calloc belongs?


What is the difference between member function and normal function?

What is the difference between malloc() and calloc()?

What if happen when you allocate memory by using malloc or calloc when the momory is not available contigiously?

malloc/calloc/realloc will return NULL

What is the difference between calloc and malloc? try this. =)

What is the difference between Malloc and calloc in C and JAVA?

In C, malloc is used to reserve a predetermined size of memory. void * malloc ( size_t size ); calloc is used to reserve a chunk of memory large enough to store num elements, each of a predetermined size. void * calloc ( size_t num, size_t size ); To create a char array of size 10 you can do it in one of two ways: char* mChars = malloc( 10 * sizeof(char) ); char* cChars = calloc( 10, sizeof(char) ); There is no concept of malloc or calloc in Java.

Contiguous memory allocation program in Linux?

malloc or calloc

Difference between malloc and alloc?

alloc is used as header file while using malloc and calloc functions in C prog.The definition of malloc function is in the alloc.h file.It's stdlib.h to be more precise

In which way calloc is better than malloc?

What calloc does is: void *calloc (size_t s1, size_t s2) { size_t s= s1*s2; void *p= malloc (s); if (p && s) memset (p, 0, s); return p; }

What is memory allocation in C?

It's function malloc (or calloc, realloc).

71 Which function should be used to free the memory allocated by calloc?

free() is a function used to free the memory allocated dynamically ,by both malloc and calloc functions. free(ptr): ptr is a pointer to a memory block which has already been creeated by malloc or calloc.

Which function should be used to free the memory allocated by calloc?

Use the free function to release memory that was previously allocated by malloc, calloc or realloc.

Use of malloc and calloc?

AnswerThe use of malloc and calloc is dynamic memory allocation. malloc allocates memory in bytes whereas calloc allocates memory in blocks. calloc initializes the allocated memory to zero. Both differs in number of arguments also. malloc takes only one argument and allocates the memory in bytes as given in the argument. calloc takes two arguments, number of variables to be allocated and size of each variable. Another difference is how the two functions deal with memory alignment.Actually malloc allocates a block of size bytes from memory heap. It allows a programto allocate memory as its needed, and in the exact amount needed . Where as calloc provides access to the C memory heap, which is available for dynamic allocation ofvariable-sized block of memory.

People also asked