InterviewSolution
Saved Bookmarks
| 1. |
What is Void Pointer in Embedded C and why is it used? |
|
Answer» Void pointers are those pointers that POINT to a variable of any type. It is a GENERIC pointer as it is not DEPENDENT on any of the inbuilt or user-defined data types while referencing. During dereferencing of the pointer, we require the correct data type to which the data needs to be dereferenced. For EXAMPLE: int num1 = 20; //variable of int datatype void *ptr; //Void Pointer*ptr = &num1; //Point the pointer to int dataprint("%d",(*(int*)ptr)); //Dereferencing requires specific data type char c = 'a';*ptr = &c; //Same void pointer can be used to point to data of different type -> reusabilityprint("%c",(*(char*)ptr));Void pointers are used mainly because of their nature of re-usability. It is reusable because any type of data can be STORED. |
|