calloc v/s malloc and time efficiency

前端 未结 7 1219
抹茶落季
抹茶落季 2021-02-04 08:12

I\'ve read with interest the post C difference between malloc and calloc. I\'m using malloc in my code and would like to know what difference I\'ll have using calloc instead.

7条回答
  •  -上瘾入骨i
    2021-02-04 08:52

    malloc differ by calloc by two reason

    1. malloc takes one argument whereas calloc takes two argument

    2. malloc is faster than calloc reason is that malloc processed single dimensional array to pointer format whereas calloc takes double dimensional array and before processed it converts to single dimensional array then to pointer format.

    I think that, that's why malloc processing faster as compared to calloc

提交回复
热议问题