So I was going through some interview questions and I came across one about void and null pointers, which claims:
a pointer with no return type is cal
Please, tell us: whats the difference:
If you come up with these, you'l be able to grasp null vs void* dillema.
The linked article is simply wrong. Its first sentence:
a pointer with no return type is called a null pointer
is triggering all sorts of alarms for me. This is a highly confused piece of writing.
You are almost correct. "Pointer to void" is a type (not a "return type"). Values of any type can be returned by functions, and thus be (the function's) return type.
A null pointer is a pointer that, regardless of its type, is pointing at the null object, which is not any valid object that can be created. A null pointer can be said to point at "nothing".
A pointer to void can also be null;
void *nothing = 0;
is perfectly valid code, and just says that this pointer is capable of pointing a an untyped object, but right now it isn't.
null pointer is point to 0x000000(which is incorrect to access pointer), while void pointer is a correct pointer to an unspecified type(void *
). However, void pointer can be null pointer, but then unreferencing the pointer will generate error.