Void Pointers are -
- General Purpose
- Stores the address of any type of variable
Why to use Void Pointers ?
float *ptr; int num; ptr = &num ; // Illegal Use of Pointer
So in order to increase the re-usability of the Pointer it is declared as void Pointer.
De-Referencing void Pointer :
Suppose - ptr is Void Pointer
- inum is integer
- cnum is character
- fnum is float
Whose Address is stored in Void Pointer ? | How to De-Reference it ? |
Integer | *((int*)ptr) |
Charcter | *((char*)ptr) |
Floating | *((float*)ptr) |
#includemain() { int inum = 8 , temp ; float fnum = 67.7; void *ptr; ptr = &inum; // Assign address of integer to void pointer temp = *((int*)ptr);
printf("\nThe valu of inum = ",temp); }
Output :
8
0 Comments:
Post a Comment
Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email