假设我有一个带有 head 指针的链表节点,并且我将 head 传递给其他一些函数 像测试(节点* np)
如果我在这个函数测试中释放 np 并且 head 可能指向节点,也可能不指向节点,会发生什么情况?
最佳答案
根据 C 标准,使用带有不正确指针的 free
是未定义的行为:
7.22.3.3 The
free
function....
The
free
function causes the space pointed to byptr
to be deallocated, that is, made available for further allocation. Ifptr
is a null pointer, no action occurs. Otherwise, if the argument does not match a pointer earlier returned by a memory management function, or if the space has been deallocated by a call tofree
orrealloc
, the behavior is undefined.
关于c - free() 函数的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26452807/