【发布时间】:2014-03-31 04:35:11
【问题描述】:
C - initialize array of structs
您好,我对这个问题有疑问(但我没有足够的代表来评论其中一个答案)。
在@pmg 的最佳答案中,他说你需要做
student* students = malloc(numStudents * sizeof *students);
首先,这是否等同于/简写
student* students = malloc(numStudents * sizeof(*students));
如果是这样,你为什么要 sizeof(*students) 而不是 sizeof(student)?
没有人对此发表评论或指责他,所以我假设他正在写作,请尽可能详细地说明两者之间的区别。我真的很想了解它。
【问题讨论】:
标签: c arrays struct malloc allocation