I am a complete novice to C, and during my university work I’ve come across comments in code that often refer to de-referencing a NULL pointer. I do have a background in C#, I’ve been getting by that this might be similar to a “NullReferenceException” that you get in .Net, but now I am having serious doubts.

有人可以用外行的话向我解释一下这到底是什么以及为什么它不好吗?

答案

ANULL指针指向不存在的内存。0x00000000或任何其他实现定义的值(只要它永远不能是真实地址)。*运算符是解引用运算符:

int a, b, c; // some integers
int *pi;     // a pointer to an integer

a = 5;
pi = &a; // pi points to a
b = *pi; // b is now 5
pi = NULL;
c = *pi; // this is a NULL pointer dereference

这与NullReferenceException在C语言中

来自: stackoverflow.com