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

Is it possible for a member function to use delete this?

1135


what is Loop function? What are different types of Loops?

1279


Can you please explain the difference between using macro and inline functions?

1093


What do you mean by inheritance in c++?

1140


What is c++ code?

1176


Can a list of string be stored within a two dimensional array?

1042


When are exception objects created?

1124


Explain deep copy?

1105


What apps are written in c++?

1141


What is the difference between public, private, and protected access?

1129


What are proxy objects in c++?

1236


What is a c++ class?

1151


What is the this pointer?

1165


Which bitwise operator is used to check whether a particular bit is on or off?

1117


Name the operators that cannot be overloaded in C++?

1113