From Wikipedia:
malloc() does not initialize the memory allocated, while calloc() guarantees that all bytes of the allocated memory block have been initialized to 0.
I understand that malloc
doesn't initialize the memory to anything, but I have to wonder, why is this the case? Was there a specific reason behind this design decision? It seems like a bit of an antipattern to use calloc(sizeof(T), 1)
in my humble opinion and I want to understand the intention.