4 ms·
> ...Why is it important to initialize memory to 0's before we use it? I guess, when writing in C, memset/calloc to 0 is a practical way to blanket-initialize
by zoomablemind 4y ago
> ...Why is it important to initialize memory to 0's before we use it?
I guess, when writing in C, memset/calloc to 0 is a practical way to blanket-initialize all members of an object, say, pointer vars could then be safely checked against zero (NULL) to test whether it's been assigned or alloc'ed, strings emptied, counts zeroed, so would be flags. Convenient!
Basically, it's a shortcut with structured objects to avoid spelling out and initialising individual variables explicitly.