What is the difference between null pointer and void pointer
Answer Posted / abi
Yes there are differences between a null pointer and a void
pointer. As you know that a pointer holds the memory address
of any variable . So we can say for a null pointer that :
- A null pointer can be of any primitive type(e.g - int *
,char * etc)
-However a null pointer does not point to any memory
location , i.e. it does not contain a reference of any
variable/value. Hence we may state that it has a NULL as its
value making it a null pointer.
Where as in case of a void pointer we can say :
- void pointer is always of type void *
- Mainly such pointers are used for dynamic memory
allocations (using malloc(), calloc() and realloc()
functions) , where memory block reserved is pointer to by a
void pointer and as the pointer value is returned it has to
be explicitly type casted to a particular desired type.
for e.g
int * ptr;
ptr=(int *) malloc(sizeof(int));
[ Here malloc () returns a pointer of void * type(i.e a void
pointer) which is type casted to int * as per our requirement ]
Is This Answer Correct ? | 15 Yes | 1 No |
Post New Answer View All Answers
Explain how can you avoid including a header more than once?
What is the use of pragma in embedded c?
What is the modulus operator?
Explain what are the different data types in c?
How do you define CONSTANT in C?
If i have an array 0 to 99 i.e,(Size 100) I place the values 1 to 100 randomly like a[0]=29,a[1]=56 upto array[99].. the values are only between 1 to 100. getting the array values by using scanf.. If i entered one wrong element value line a[56]=108. how can i find it.. and also how to find the missing value in 1 to 100.. and i want to replace the missing values.. any one of them know please post your answer..
How to Throw some light on the splay trees?
How important is structure in life?
What are qualifiers?
How do we declare variables in c?
What is this infamous null pointer, anyway?
State the difference between realloc and free.
How do you write a program which produces its own source code as output?
I have seen function declarations that look like this
Is c programming hard?