Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Are stack-allocated arrays in C zero'd out by default in C?

When I allocate memory on the heap with malloc(), there might be garbage in that memory unless I use calloc() or memset() to zero it out. Is this the same situation for the stack, or can I safely assume anything I allocate on the stack won’t have garbage in it? Also, does this differ on different systems or OSes?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It is the same situation on the stack.

Unless you explicitly initialize the values of variables to zero or some other value, variables with automatic storage duration will have indeterminate values.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading