WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c
file management?

Answers were Sorted based on User's Feedback



WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management? ..

Answer / karthik

Malloc() is used to allocate a block of memory

Calloc() is used to allocate a block of memory and initialize it.

Is This Answer Correct ?    2 Yes 2 No

WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management? ..

Answer / jayakrishnan d

1.malloc is only one argument function while malloc is a
two arguments function.
2.malloc allocates bytes of memory while calloc allocates
array of memory.
3.malloc does not initialize the size of allocated memory ie
gabage value while calloc is initialize size of allocated
memory to '0'.

Is This Answer Correct ?    0 Yes 0 No

WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management? ..

Answer / kaushik

malloc takes only one argument but calloc takes two orguments
malloc takes garbage value initial but calloc takes zero initial value,
calloc()and malloc() also returns NULL if there is not sufficient memory available in the heap

Is This Answer Correct ?    0 Yes 0 No

WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management? ..

Answer / tinku

There are two differences.
First, is in the number of arguments.
Malloc() takes a single argument (memory required in bytes),
Calloc() needs two arguments.
Secondly, malloc() does not initialize the memory allocated, while
calloc() initializes the allocated memory to ZERO.


calloc() allocates a memory area, the length will be the product of its parameters. calloc fills the memory with ZERO's and returns a pointer to first byte. If it fails to locate enough space it returns a NULL pointer.
Syntax: ptr_var=(cast_type *)calloc(no_of_blocks , size_of_each_block);
i.e. ptr_var=(type *)calloc(n,s);

malloc() allocates a single block of memory of REQUSTED SIZE and returns a pointer to first byte. If it fails to locate requsted amount of memory it returns a null pointer.
Syntax: ptr_var=(cast_type *)malloc(Size_in_bytes);

Is This Answer Correct ?    0 Yes 0 No

WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management? ..

Answer / nazia wasim

malloc and calloc both are used to allocate
memory dynamically but the difference is
malloc allocates single block of memory and
calloc allocates multiple block of memory as
per the requirement.

Is This Answer Correct ?    0 Yes 0 No

WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management? ..

Answer / datta khilari

1.malloc() takes one argument and allocates memory in a
bytes and return to the pointer.
1.calloc() takes two argument and allocates memory in a
blocks and return to the pointer.

Is This Answer Correct ?    0 Yes 0 No

WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management? ..

Answer / sudhir

malloc used to static memory allocation &
calloc is used to dyanmic memory allocation

Is This Answer Correct ?    1 Yes 2 No

WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management? ..

Answer / shirish

malloc: malloc create the single block of given size by user
calloc: calloc creates multiple blocks of given size

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More C Interview Questions

can we write a c program with out using main

3 Answers  


What is the purpose of Scanf Print, getchar, putchar, function?

3 Answers  


Explain how can I avoid the abort, retry, fail messages?

0 Answers  


Write a progarm to find the length of string using switch case?

0 Answers   TCS,


Why is structure important for a child?

0 Answers  






How can you avoid including a header more than once?

0 Answers  


What is data type long in c?

0 Answers  


What is the difference between array and pointer?

0 Answers  


I need to take a sentence from input and sort the words alphabetically using the C programming language. Note: This is C not C++. qsort and strtok not allowed

4 Answers   Aspire,


How does sizeof know array size?

0 Answers  


what would be the output of the follwing struct st { char name[20]; int i; float f; }; main() { struct st emp = {"forum"}; printf("%d %f",emp.i,emp.f); }

4 Answers  


Give the logic for this #include<stdio.h> #include<conio.h> void main() { clrscr(); int a=10,b; b=++a + ++a; printf("%d", b); getch(); } Output: 24......How?

2 Answers   Accenture,


Categories