I had forgotten about calloc for the longest time, but I was recently reminded of it. Now i'm curious, what would be the difference between malloc(numElems * elemSize);
and calloc(numElems, elemSize);
? If my knowledge of arrays is correct, there shouldn't be any difference in the memory allocated.
death_oclock 103 Posting Whiz
Recommended Answers
Jump to PostConceptually, calloc works like this:
void *calloc ( size_t n, size_t size ) { void *mem = malloc ( n * size ); memset ( mem, 0, n * size ); return mem; }
All 3 Replies
Rashakil Fol 978 Super Senior Demiposter Team Colleague
Narue 5,707 Bad Cop Team Colleague
death_oclock 103 Posting Whiz
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.