本文介绍了是否有必要类型转换malloc和释放calloc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I was googling to find out the reason for type-casting of malloc and calloc. But, i only found type-casting of malloc is not necessary since it return void pointer but, what about calloc. This is the same reason for calloc too ???

Now, if we move back to first point, about return value of malloc and calloc. Then, i found that, both are returning the allocated spaces. So, i'm little bit confused here. So, my questions are

解决方案

It is a pointer to void (void*).

No, because the conversion from a pointer to void to a pointer to object is implicit.

It is right for both malloc and calloc.

这篇关于是否有必要类型转换malloc和释放calloc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 08:00