Ç - 指针内存分配 [英] C - Pointer memory allocation
本文介绍了Ç - 指针内存分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可有人请向我解释
int *x = malloc(sizeof(int));
&放大器;&安培;
&&
int *x = (int*)malloc(sizeof(int));
谢谢!
推荐答案
不同的是,你是铸造在第二个例子中返回的malloc()
。 的malloc()
返回无效*
指针,它会自动,安全地促进了在这种情况下,任何其他指针类型。
The difference is that you are casting the return of malloc()
in the second example. malloc()
returns a void*
pointer, which is automatically and safely promoted to any other pointer type in this case.
因此,在此情况下,不需要铸造和不应该这样做。这里检查。
Therefore casting in this case is not required and should not be done. Check here.
这篇关于Ç - 指针内存分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文