Possible Duplicate:
What's the difference between a null pointer and a void pointer?
What is the difference between a pointer to void and a NULL pointer in C? Or are they the same?
A void is nothing but takes up space; null is nothing at all. In other words, you could measure a void but null offers nothing to measure. 4.1 Void is used to indicate that a function/method does not return any data type. Null indicates that a pointer variable is not pointing to any address.
void* is just a pointer to an undefined type. A void* can be set to any memory location. A NULL pointer is a any pointer which is set to NULL (0). So yes, they are different, because a void pointer is a datatype, and a NULL pointer refers to any pointer which is set to NULL.
A void pointer is a pointer that has no associated data type with it. A void pointer can hold address of any type and can be typecasted to any type.
Void means that a method does not return a result. Null means that an object reference does not currently reference an object (in other words, it references nothing).
In C, there is void
, void
pointer and NULL
pointer.
void
is absence of type. I.E. a function returning a void
type is a function that returns nothing.void
pointer: is a pointer to a memory location whose type can be anything: a structure, an int, a float, you name it.NULL
pointer is a pointer to location 0x00
, that is, no location. Pointing to nothing.Examples:
void
function:
void printHello()
{
printf("Hello");
}
void
pointer:
void *malloc(size_t si)
{
// malloc is a function that could return a pointer to anything
}
NULL
pointer:
char *s = NULL;
// s pointer points to nowhere (nothing)
void
is a datatype. void*
is just a pointer to an undefined type. A void*
can be set to any memory location. A NULL pointer is a any pointer which is set to NULL (0).
So yes, they are different, because a void pointer is a datatype, and a NULL pointer refers to any pointer which is set to NULL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With