空指针的地址是什么?

Kuk*_*pox 2 c++ null pointers

这是一个非常基本的问题,但我一直在寻找无处可寻的答案.

请考虑以下代码:

myFunction(MyObject** obj) {...}

int main()
{
  MyObject *obj = NULL;
  myFunction(&obj);
}
Run Code Online (Sandbox Code Playgroud)

这是什么结果?

&objNULL吗?未定义?是段错吗?

Yog*_*esh 5

不,&obj不会是NULL,它将是保存"obj值"的内存地址,指向MyObject的指针.它很简单

int x = 0;
int *ptrTox = &x;
Run Code Online (Sandbox Code Playgroud)

在这种情况下,ptrTox将包含x的地址,而不是零.它可以是任何有效的地址.