如何在C中删除空指针? [英] How to delete a null pointer in C?

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

问题描述





如何在C中删除空指针?我可以有一个示例代码。

解决方案

你不能'删除'一个空指针。

严格来说, C 编程语言没有删除(它是 C ++ 关键字),它只是提供免费 [ ^ ]功能。在任何情况下,空指针上的 free 什么也不做。


空指针表示没有任何东西 - 它指向什么都没有。所以你不能删除或释放它,因为你没有分配它。



很可能,这是你得到的错误信息您的代码中的问题 - 您正在尝试使用未指定地址的指针,因此系统报告空指针错误。

这样的事情:

  int  x =  77 ; 
int * p;
x = x + * p;

使用调试器:在函数的第一行放置一个断点,显示错误并逐步执行代码,查看变量以及确切的内容上。导致问题的原因应该是相当明显的。



我们无法为您做到这一点:我们无法看到您的屏幕,访问您的硬盘或阅读你的想法! :笑:


Hi,

How to delete a null pointer in C? Can i have a sample code.

解决方案

You cannot 'delete' a null pointer.
Strictly speaking, the C programming language has no delete (it is a C++ keyword), it just provides the free[^] function. In any case, free on a null pointer does nothing.


A null pointer indicates that there is "nothing there" - it points at nothing. So you can't delete or free it, because you didn't assign it.

Most likely, this is an error message you are getting as a result of a problem in your code - you are trying to use a pointer that you have not assigned an address into, so the system is reporting a "null pointer" error.
Something like this:

int x = 77;
int *p;
x = x + *p;

Use the debugger: put a breakpoint on the first line of the function that shows the error and step through your code, looking at the variables and exactly what is going on. It should be fairly obvious what is causing the problem.

We can't do that for you: we can't see your screen, access your HDD, or read your mind! :laugh:


这篇关于如何在C中删除空指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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