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


Please Help Members By Posting Answers For Below Questions

Who developed c language?

643


void main(){ int a; a=1; while(a-->=1) while(a-->=0); printf("%d",a); }

1262


What are c identifiers?

630


Hai what is the different types of versions and their differences

1492


What is the size of a union variable?

603






What do you mean by command line argument?

647


Hello. How to write a C program to check and display president party like if i type in the console "biden" and hit enter the output shoud be : "biden is democrat" and if i type "trump" and hit enter the output shoud be: "trump is republican"

1583


What is the difference between int main and void main?

576


why use functions a) writing functions avoids rewriting the same code over and over b) using functions it becomes easier to write programs and keep track of what they are doing c) a & b d) none of the above

655


how many errors in c explain deply

1632


Is there any algorithm to search a string in link list in the minimum time?(please do not suggest the usual method of traversing the link list)

1866


What does the file stdio.h contain?

608


What are the preprocessor categories?

640


What is the -> in c?

586


How do you determine whether to use a stream function or a low-level function?

650