Difference between malloc and calloc?

Difference between malloc and calloc?

Some main and important difference b/n malloc and calloc are given below:

malloc is use for memory allocation and initialize garbage values. where as calloc is same as malloc but it initialize 0 value.
example:

// This allocats 200 ints, it doesn't initialize the memory:
int *m = malloc(200*sizeof(int));

// This, too, allocates 200 ints, but initializes the memory
// to zero:
int *c = calloc(200,sizeof(int));
 

By:Vivek Kr. Agarwal
Date:2003-01-09 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related C Subjective Links

C Subjective interview questions and answers for experienced and fresher