本文介绍了未初始化指针和空指针的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

空指针和未初始化指针有什么区别吗?这个问题是在一次采访中被问到的.你能解释一下它们之间的区别吗?

Is there any difference between null pointer and uninitialized pointer?This question was asked in one of the interviews.Could you please explain the difference that they have?

推荐答案

取一个未初始化的指针:

Take an uninitialized pointer:

int* ptr;//points to any location in memory

取一个空指针:

int* ptr = NULL;//normally points to 0x0 (0)

如果取消引用,两者都会导致未定义的行为.NULL 通常定义为 0.

Both would cause undefined behaviour if dereferenced. NULL is often defined as 0.

这篇关于未初始化指针和空指针的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 07:38