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 "calloc" and "malloc"?

Answer Posted / saugat biswas

Malloc:
Malloc allocates memory but does not initialize it.
Example: char *szPtr = ( char* ) malloc( sizeof( char ) *
100 );
Here szPtr is assigned 100 bytes. But the memory is not
initialized. It contains garbage.

Calloc:
Allocates a block of memory for an array of 'n' elements,
each of them 'l' bytes long, and initializes all its bits
to zero.
Example: char *szPtr = ( char* ) calloc( 100, sizeof(
char ));
Here szPtr is assigned 100 bytes & the memory is
initialized to 0.

Is This Answer Correct ?    11 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between global variables and local variable

995


Why is c++ called oops?

1076


What are the 3 levels of programming languages?

994


Where the memory to the static variables is allocated?

1002


When is dynamic checking necessary?

1042


How can a struct in c++ differs from a struct in c?

983


Who was the creator of c++?

994


Using a smart pointer can we iterate through a container?

1022


Explain the difference between overloading and overriding?

1082


Explain the properties and principles of oop.

960


What does iomanip mean in c++?

1130


What are the three forms of cin.get() and what are their differences?

1153


How would you use the functions memcpy(), memset(), memmove()?

1033


What does 7/9*9 equal ? a) 1 b) 0.08642 c) 0

909


Which programming language's unsatisfactory performance led to the discovery of c++?

1261