Void pointer

Explain about void pointer and it's real time usage in Business

Questions by meefriend4ever   answers by meefriend4ever

Showing Answers 1 - 2 of 2 Answers

Void pointer are something like you put your stuff like shoes, bag, shirt in your suitcase. and then you just take out all that stuff from suitcase.
so we can cast any pointer to void*, and after we can case void* to its original pointer.
if we try to cast it in any other kind of point instead of the original one, the behaviour is undefined.

  Was this answer useful?  Yes

wael.salman

  • Jul 16th, 2008
 

Pointer to void, or a void pointer, is a special type of pointer that has a great facility of pointing to any data type.

Example:

int i;
float f;
int* exf;
float* test;
then
exf=&i;//Corerct-exf is pointer to int and it is pointing to int
- &i
exf=&f;//Incorrect - integer pointer pointing to float

but if you define something like this - void pointer

void* sample;

so you can point by sample to any data float or int or anything

sample = &i //Correct
sample = &f //Correct


limitations :

The programmer must note that void pointers cannot be de-referenced in the same manner. Direct dereferencing of void pointer is not permitted. The programmer must change the pointer to void as any other pointer type that points to valid data types such as, int, char, float and then dereference it. This conversion of pointer to some other valid data type is achieved by using the concept of type-casting (refer to type-casting section of this tutorial).



Thank you
Wael


Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions