问题描述
关于C指针的求职面试问题之一此处为以下内容:什么是空指针分配错误?
One of job interview questions on C pointers here is the following: what is null pointer assignment error?
我已经搜索了一段时间,没有看到任何合理的解释.那是什么?试图写一个空指针?某些特定于体系结构或环境的东西?那个错误到底是什么?
I've googled for a while and don't see any reasonable explanation. What is that? Trying to write through a null pointer? Something architecture- or environment-specific? What exactly is that error?
推荐答案
http://www.faqs.org/qa/qa-3786.html
示例代码:
int* ptr = NULL;
*ptr = 3;
说明:
在几乎每个系统上,地址0都是保留的.系统不允许您写入该位置.如果尝试尝试,则会遇到运行时异常(访问冲突,分段错误等).
Explanation:
On almost every system, address 0 is reserved. System won't allow you to write to that location. If you try, you will get a runtime exception (access violation, segmentation fault, etc.).
这篇关于什么是“空指针分配错误"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!