Void Pointers
Limitation of Void Pointers:
1. They can't be dereferenced.
Reason: Each variable type takes different amount of memory. So, in order to read the actual value stored there, the compiler has to know how many consecutive memory locations to read in order to get the full value.
2. We can't perform arithmetic operations on them.
Reason: The compiler cannot know how many bytes ahead the next variable is located.
Void pointers are mainly used to keep addresses that we have to convert later on to a specific pointer type, before using them.
1. They can't be dereferenced.
Reason: Each variable type takes different amount of memory. So, in order to read the actual value stored there, the compiler has to know how many consecutive memory locations to read in order to get the full value.
Dereferencing a pointer means getting the value that is stored in the memory location pointed by the pointer. The operator * is used to do this, and is called the dereferencing operator.
Reason: The compiler cannot know how many bytes ahead the next variable is located.
Void pointers are mainly used to keep addresses that we have to convert later on to a specific pointer type, before using them.
Comments
Post a Comment