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
How many levels of indirection in pointers can you have in a single declaration?
What is an array? What the different types of arrays in c?
What happens if a header file is included twice?
What's the difference between constant char *p and char * constant p?
What are valid signatures for the Main function?
What is %s and %d in c?
What is difference between %d and %i in c?
How do we declare variables in c?
What is strcmp in c?
What are qualifiers?
Write the syntax and purpose of a switch statement in C.
What is bss in c?
How can I change the size of the dynamically allocated array?
What is the difference between c and python?
a) Identify the following declarations. Ex. int i (integer variable) float a[l0](array of 10 real nos) int (*f())() void *f int (*f()) [] void *f int f[] [] [] char *(*f) () int (*f[]) [] float(*f) [] [] float **f int ******f