自已定义的struct的一个类型有办法申请一个动态类型的类似动态数组一样的吗
答案:2 悬赏:60
解决时间 2021-04-28 04:51
- 提问者网友:我喜歡係
- 2021-04-27 13:51
自已定义的struct的一个类型有办法申请一个动态类型的类似动态数组一样的吗
最佳答案
- 二级知识专家网友:孤伤未赏
- 2021-04-27 14:18
可以。
比如
struct type
{
int a;
char b;
};
//...
struct type* array = (struct type*)malloc( N * sizeof(struct type));//长度为N的数组
比如
struct type
{
int a;
char b;
};
//...
struct type* array = (struct type*)malloc( N * sizeof(struct type));//长度为N的数组
全部回答
- 1楼网友:山鬼偶尔也合群
- 2021-04-27 15:33
typedef struct b
{
...
}b;
strcut
{
b *bp;
....
}a;
a.bp= (b *)malloc( sizeof(b)*10 ); //动态分配10个
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息