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 does free() know explain how much memory to release?
What is c standard library?
What language is windows 1.0 written?
Can you subtract pointers from each other? Why would you?
An arrangement of information in memory in such a way that it can be easily accessed and processed by a programming language a) string b) data structure c) pointers d) array
Explain main function in c?
What is || operator and how does it function in a program?
Define recursion in c.
main use of recursive function a) processing speed high b) reduce program length/reduce repeated statements c) if you do not, use iterative methods like, for, while or do-while d) all the above
How can I call fortran?
what is the c source code for the below output? 10 10 10 10 10 10 10 10 10 10 9 9 7 6 6 6 6 6 6 9 7 5 9 7 3 2 2 5 9 7 3 1 5 9 7 3 5 9 7 4 4 4 4 5 9 7 8 8 8 8 8 8 8 8 9
What the different types of arrays in c?
What's the right way to use errno?
Are the outer parentheses in return statements really optional?
What is "Duff's Device"?