Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Are enumerations really portable?

1029


What is include directive in c?

1159


Why is c so important?

1065


Explain 'bus error'?

1098


Subtract Two Number Without Using Subtraction Operator

853


typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none

1199


What are two dimensional arrays alternatively called as?

1189


what is uses of .net

1742


What is c programming structure?

1204


What is scanf_s in c?

1125


Where is volatile variable stored?

1089


Explain the difference between getch() and getche() in c?

1000


How many types of operators are there in c?

1040


What do you mean by a local block?

1087


Write a c program to build a heap method using Pointer to function and pointer to structure ?

4691