Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Is void a keyword in c?

986


Draw a flowchart to produce a printed list of all the students over the age of 20 in a class .The input records contains the name and age of students. Assume a sentinel value of 99 for the age field of the trailer record

5203


What is call by reference in functions?

1432


In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?

1222


Explain how can I pad a string to a known length?

1189


What is the equivalent code of the following statement in WHILE LOOP format?

1295


Why pointers are used in c?

1006


Why do we need a structure?

1037


Under what circumstances does a name clash occur?

1198


Why structure is used in c?

1186


What is the difference between typedef and #define?

1050


Tell me when would you use a pointer to a function?

1049


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

1720


What is identifier in c?

1007


How can I split up a string into whitespace-separated fields?

1052