【发布时间】:2017-01-23 21:15:49
【问题描述】:
我是 C 的新手,在弄清楚如何将连续内存分配给结构数组时遇到了麻烦。在这个作业中,我们得到了一个代码的外壳,剩下的必须填写。因此,我无法更改变量名称或函数原型。这是给我的:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
struct student {
int id;
int score;
};
struct student *allocate() {
/* Allocate memory for ten students */
/* return the pointer */
}
int main() {
struct student *stud = allocate();
return 0;
}
我只是不确定如何去做那些 cmets 在 allocate 函数中所说的操作。
【问题讨论】:
-
获得更好的课程。不鼓励函数签名,将从未来的标准中删除。使用原型风格,例如
int main(void).
标签: c arrays memory-management struct contiguous