【发布时间】:2011-02-26 11:01:38
【问题描述】:
// the malloc style, which returns a pointer:
struct Cat *newCat = malloc(sizeof(struct Cat));
// no malloc...but isn't it actually the same thing? uses memory as well, or not?
struct Cat cat = {520.0f, 680.0f, NULL};
基本上,我可以通过这两种方式获得一个初始化的结构。我的猜测是:这是一回事,但是当我使用 malloc 时,我还必须 free() 。在第二种情况下我不必考虑内存,因为我不调用malloc。也许吧。
什么时候应该使用 malloc 样式,什么时候使用另一个?
【问题讨论】:
标签: c