Do I have to call memset after I allocated new memory using malloc

后端 未结 4 2014
情书的邮戳
情书的邮戳 2020-12-16 18:02
#include \"stdlib.h\"
#include \"stdio.h\"
#include \"string.h\"
int main(int argc, char* argv[])
{
    int *test = malloc(15 * sizeof(int));
    for(int i = 0;i <         


        
4条回答
  •  长情又很酷
    2020-12-16 18:25

    For performance reasons, malloc() makes no guarantee regarding the contents of newly allocated memory. It might be zeros, it might be random data, it might be anything. If you want malloc'ed memory to have a specific value, then it is up to you do it.

提交回复
热议问题