假设列表是某种结构
list *temp;
temp = new list;
上面是用 C++ 写的,这在 C 中有等效项吗?
最佳答案
list *temp;
temp = malloc(sizeof(list));
[...]
free(temp);
C 没有new
关键字——您必须手动分配和释放您想要使用的内存。 new
也做了一些 work behind the scenes ,比如调用构造函数并返回正确的指针类型 - malloc
不包括这些,必须由程序员处理。
关于c++ - 等价于 C++ 中结构初始化的 C 编程语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58367822/