c - 释放空指针

标签 c pointers

如果我们试图释放一个指向 NULL 的指针,内存中会发生什么? 这是否有效?

为什么它不显示任何警告/错误消息?

最佳答案

摘自 C99 第 7.20.3.2 节:free 函数

概要

 1 #include <stdlib.h>
   void free(void *ptr);

描述

2 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.

关于c - 释放空指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50113535/

相关文章:

c - Dart RawSockets 有什么用?

c - 在 C 中反转字符串 - 内存方向

c - 错误 C2099 : initializer is not a constant

c++ - 多重继承指针比较

c++ - 分配给 `char* x = new char[32]` 的内存过多

c - Linux Socket 系统调用 "accept"永远不会返回?

c - 如何在 C 中的结构中初始化结构?

c - 递增 float 组指针

c - 指针和结构变量

c++ - 返回指向intent(in)参数的指针