+ 3
Void pointer vs NULL pointer
What is the difference between void pointer and null pointer in C programming?
7 Antworten
+ 11
'void' is a data type, which means that the memory location the pointer points to has no specific type, however, it can be casted to a data type if required.
'NULL' is not quite a data type, but rather a value. It's a macro that is used to indicate that the pointer currently does not point to a memory location.
This also means that a void pointer can be null, and a null pointer can be of type void.
Further reference:
https://www.quora.com/What-is-difference-between-null-pointer-and-void-pointer-in-C
https://stackoverflow.com/questions/4334831/what-is-a-void-pointer-and-what-is-a-null-pointer
+ 8
A pointer pointing to null is a null pointer, meaning it doesn't point to anything.
A void pointer can point to any address without knowing the type that it is pointing to.
A void pointer can point to null in which case the void pointer is a null pointer.
Because a void pointer does not know what type it is pointing to you cannot dereference it without explicitly casting it.
+ 3
@Shadow , Thank you!!
+ 3
@Dennis, Thank you!
0
how do you initialize a pointer as nul?
0
Syntax for null pointer initialization ..
Syntax: <data type> *<variable name> = NULL;
Example: int *ptr = NULL;
char *ptr = '\0';
0
Examples of null pointer and void