释放空指针 [英] freeing a null pointer

查看:209
本文介绍了释放空指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

内存里,会发生什么,如果我们试图释放其指向NULL指针?
那是永远有效吗?

What happens inside memory if we try to free a pointer which is pointing to NULL? Is that ever valid?

为什么它没有表现出任何的警告/错误信息?

Why does it not show any warning/error messages?

推荐答案

从C99部分7.20.3.2:在免费功能

From C99 section 7.20.3.2 : The free function

简介

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

说明

2的免费功能使空间ptr指向要被释放,也就是说,国产
  可用于进一步分配。 若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.

这篇关于释放空指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆