I am following this tutorial (http://theocacao.com/document.page/234). I am confused about this paragraph, mainly the lines relating to calloc:
We can also use a variation of the malloc function, called calloc. The calloc function takes two arguments, a value count and the base value size. It also clears the memory before returning a pointer, which is useful in avoiding unpredictable behavior and crashes in certain cases:
That last line confuses me. What does it mean to clear the memory?
The function calloc will ensure all bytes in the memory returned are set to 0. malloc makes no such guarantees. The data it returns can, and will, consist of seemingly random data.
The distinction is very useful for initialization of data members. If 0 is a good default for all values in a struct then calloc can simplify struct creation.
vs.
Null checking omitted for clarity.