Saturday, December 3, 2011

Easy-4


void main()
{
int *mptr, *cptr;
mptr = (int*)malloc(sizeof(int));                               //Output: some garbage values
printf(“%d”,*mptr);
int *cptr = (int*)calloc(sizeof(int),1);                      // Output=0
printf(“%d”,*cptr);
}

The above statements return garbage values and a zero in the next.
So much for understanding a small difference between malloc() and calloc().
See the differences in arguments and the returned values.

No comments:

Post a Comment