Difference between malloc and calloc?

后端 未结 14 1856
感情败类
感情败类 2020-11-22 03:40

What is the difference between doing:

ptr = (char **) malloc (MAXELEMS * sizeof(char *));

or:

ptr = (char **) calloc (MAXEL         


        
14条回答
  •  感动是毒
    2020-11-22 04:07

    The calloc() function that is declared in the header offers a couple of advantages over the malloc() function.

    1. It allocates memory as a number of elements of a given size, and
    2. It initializes the memory that is allocated so that all bits are zero.

提交回复
热议问题