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/2354658/

相关文章:

将 x86 转换为 Y86

c - 在 C 中使用默认值和范围约束解析命令选项

c - C : how to check for valid pointer? 中的空闲内存

c++ - 哪个指针赋值更好(C++)

C++指针声明

python - SWIG 与 python 和 C : arguments

c - 如何查看2个二叉树是否相似?

C++ 收集2 : error: ld returned 1 exit status

c++ - 尝试从方法返回指向对象的指针时出现段错误

c - 为什么程序不断打印垃圾值?