19

malloc时动态内存分配函数,以void*类型返回分配的内存区域地址
malloc函数原型
extern void*malloc(unsigned int num_bytes);
malloc函数头文件
#include
malloc函数的返回的是无类型指针,在使用时需强制转换为所需要的类型
使用完成后需释放空间
指针自身=(指针类型*)malloc(sizeof(指针类型)*数据数量)
p=(int*)malloc(sizeof(int)*n);
free函数(释放malloc函数给指针变量分配的内存空间)
使用后指针变量要重新指向null
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务