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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are variables and it what way is it different from constants?

774


Explain how are 16- and 32-bit numbers stored?

773


This is a variation of the call_me function in the previous question:call_me (myvar)int *myvar;{ *myvar += 5; }The correct way to call this function from main() will be a) call_me(myvar) b) call_me(*myvar) c) call_me(&myvar) d) expanded memory

719


Explain how many levels deep can include files be nested?

620


Linked lists -- can you tell me how to check whether a linked list is circular?

633






Find duplicates in a file containing 6 digit number (like uid) in O (n) time.

2586


Explain what are compound statements?

596


can any one please explain, how can i access hard disk(physical address)? it is possible by the use of far,near or huge pointer? if yes then please explain......

1398


What is an auto variable in c?

742


In which header file is the null macro defined?

841


What is wrong with this declaration?

604


What do you mean by keywords in c?

614


What is structure padding and packing in c?

608


To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9

2178


What do you understand by normalization of pointers?

617