我有意尝试在 C 中获取 NULL 指针,但我没有做到。这是我编写的代码:
int main(void) {
int x; //UNINITIALIZED so that it will represent "nothing"
int *null_test = &x;
printf("This should be null %p \n", null_test);
}
但它给了我一个地址:0x7fd96c300020
,它似乎不像我希望的那样是 NULL
。
为什么?我什至没有初始化x
但仍然不为空?
最佳答案
之后
int *null_test = &x;
null_test
包含 x
的地址。此地址独立于 x
的内容,即使 x
从未被初始化。
关于c - 在 C 中没有得到 NULL 指针错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41671116/