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
Who developed c language?
void main(){ int a; a=1; while(a-->=1) while(a-->=0); printf("%d",a); }
What are c identifiers?
Hai what is the different types of versions and their differences
What is the size of a union variable?
What do you mean by command line argument?
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"
What is the difference between int main and void main?
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
how many errors in c explain deply
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)
What does the file stdio.h contain?
What are the preprocessor categories?
What is the -> in c?
How do you determine whether to use a stream function or a low-level function?