我怎样才能代替使用新的使用malloc翻译

How can i instead of using the new use malloc translation

本文关键字:malloc 翻译      更新时间:2023-10-16

我在 c++ 中用这段代码创建了一个 2D 数组表。

struct person
{
int age;
char name[64];
}
person **p;
p = new person*[256];

如何只翻译部分

p = new person*[256];

使用 MALLOC 到 C 代码。

感谢

p = malloc(256*sizeof(*p));
for(size_t i=0; i< 256; i++)
{
p[i] = malloc(sizeof(**p));
}

不要忘记广告代码,如果 mallocs 没有失败,则检查。