zeroing out memory
Posted
by robUK
on Stack Overflow
See other posts from Stack Overflow
or by robUK
Published on 2010-05-21T17:35:14Z
Indexed on
2010/05/21
17:40 UTC
Read the original article
Hit count: 163
c
Hello,
gcc 4.4.4 c89
I am just wondering what most c programmers do when they want to zero out memory.
For example I have a buffer of 1024 bytes. Sometimes I do this:
char buffer[1024] = {0};
Which will zero all bytes.
However, should I declare like this and use memset?
char buffer[1024];
.
.
memset(buffer, 0, sizeof(buffer);
Is there any real reason you have to zero the memory? What is the worst that can happen by not doing it?
Many thanks for any suggestions,
© Stack Overflow or respective owner