指向C中结构的指针的内存分配

时间:2017-05-09 13:10:02

标签: c pointers malloc structure

当我使用malloc函数为C中的结构分配内存时,为什么我不必抛出函数,因为它的返回类型是void *而不是我想要的结构? 那么为什么呢:

Str *str = malloc(sizeof(Str));

而不是这个:

Str *str = (Str*)malloc(sizeof(Str));

0 个答案:

没有答案