malloc和new

98 阅读1分钟

在堆区申请内存,手动开辟手动释放; C++使用new(),默认返回为指针数据类型; C使用malloc(),但是返回值为地址,int类型,使用过程中一般使用指针类型转换;

int *p = (int *) malloc (10);\\C语言中
int *p=new(10);\\Cpp中