释放NULL指针 [英] Free a NULL pointer
问题描述
Possible Duplicate:
Does free(ptr) where ptr is NULL corrupt memory?
Is it good practice to free a NULL pointer in C?
我有一个关于释放空指针的问题.
I have a question concerning freeing a null pointer.
char *p = NULL;
free(p);
free(NULL)
会导致崩溃吗?
还是取决于编译器?
推荐答案
来自免费的手册页
void free(void *ptr);
free()函数取消分配由指向的内存分配 点如果ptr是NULL指针,则不执行任何操作.
The free() function deallocates the memory allocation pointed to by ptr. If ptr is a NULL pointer, no operation is performed.
如果您想从C手册本身获得确认
If you want to get confirmation from C manual itself
free函数使ptr指向的空间为 释放,即可供进一步分配.如果ptr是 空指针,不执行任何操作.
The free function causes the space pointed to by ptr to be deallocated, that is, made available for further allocation. If ptr is a null pointer, no action occurs.
请参见本文档的第313页
See page 313 of this document.
这篇关于释放NULL指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!