C程序申请动态结构体数组,怎么做?

如题,谢谢。
2025-04-06 18:18:00
推荐回答(3个)
回答1:

struct A
{
int a;
int b;
};
struct A *pA = NULL;
pA = (struct A *)malloc(sizeof(struct A)*N);
N为结构体个数
用完记得用free(pA)施放内存。

回答2:

假如有个student结构体,则
student a=new student[n]();就可以了 想申请多少就多少

回答3:

struct yourtype
{
};
yourtype *ptype =(yourtype *) malloc(yourtype);