小编Con*_*n97的帖子

如何为结构数组动态分配内存

我对C很新,并且无法弄清楚如何将连续内存分配给结构数组.在这个赋值中,我们给出了代码的shell,并且必须填写其余部分.因此,我无法更改变量名称或函数原型.这是给我的:

#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;
}
Run Code Online (Sandbox Code Playgroud)

我只是不确定如何去做那些评论在分配功能中所说的内容.

c arrays struct memory-management contiguous

1
推荐指数
1
解决办法
1234
查看次数

标签 统计

arrays ×1

c ×1

contiguous ×1

memory-management ×1

struct ×1