c - free() 函数的使用

标签 c pointers

假设我有一个带有 head 指针的链表节点,并且我将 head 传递给其他一些函数 像测试(节点* np)

如果我在这个函数测试中释放 np 并且 head 可能指向节点,也可能不指向节点,会发生什么情况?

最佳答案

根据 C 标准,使用带有不正确指针的 free 是未定义的行为:

7.22.3.3 The free function

....

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. 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 to free or realloc, the behavior is undefined.

关于c - free() 函数的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26452807/

相关文章:

c - GtkBuilder 忽略 .ui 文件

c - realloc函数的使用

递增指针会导致内存泄漏吗?

c - 确定转弯方向?

java - 欧氏除法中的位补运算符

c - 反向 C 字符串 - 简单的错误

c - 将内存分配给具有精确字符长度的指针

c++ - 与观察者指针共享指针

c - 双链表和void指针【find方法】

C - Lstat on/proc/pid/exe