假设列表是某种结构
list *temp;
temp = new list;
上面是c ++,在C中是否等效?
答案 0 :(得分:5)
list *temp;
temp = malloc(sizeof(list));
[...]
free(temp);
C没有new
关键字-您必须分配和释放要手动使用的内存。 new
还会做一些work behind the scenes,例如调用构造函数并返回正确的指针类型-malloc
不能解决这个问题,必须由程序员处理。