Dereferencing comes into picture whenever it is a need to access the stored value in the pointer variable. Also, there is a type of casting value which is used for dereferencing because none of the pointer value is associated with the data types. The compiler also cannot find the type of variable which is pointed by any type of void pointer. One point to keep in mind is void pointer will not support any kind of arithmetic operation.
But to serve this problem there is a need to typecast the pointer variable as well for dereferencing. The usage of typecasting is needed because there is no presence of datatype associated at the time of declaration of the pointer. So, it performs the typecasting and meets the requirement to give an intimation of the type of data type used by the void pointer at the time of declaration. Size of the void pointer is the next point of focus as a void pointer in C functions almost the same as character pointer in C which means a representation of Character type of pointer will be the same as a void pointer in C.
Also, the size will vary according to the platform being used by the pointer. Memory allocation also works in some format which means void pointer has the beauty of providing an enhancement feature of memory management with calloc and malloc functions which ultimately returns the void as return type. Therefore, these functions can be used to allocate the memory of any data type. The most important theme line of all the added advantage which pointer has is that it has the power of reusability for void pointers.
It can store any type of object and can retrieve any type of object from the defined object using the indirection operator and operator with proper typecasting. Dereferencing operator as part of the pointer can be used for easy access or manipulation of the stored data in the memory location for the pointer pointing the data type and it will have a direct impact on the value of the data type. This program illustrated the void Pointer in C as it is not associated with any data type at the time of declaration as shown in the given output.
This program is used to illustrate the dereferencing of the void pointer of C where the input is given to variable with the inception operator which is shown with the following example.
This program illustrates the void pointer in C for representing the size of integer value define with the arithmetic operator which means it manages to support the arithmetic operator in association with a void pointer. Although it needs to follow some of the standards of the GNU then only the compilation allowed will provide the necessary output as shown otherwise it will give a compilation error. This program is used to illustrate the basic concept of dereferencing with the void pointer in C and its output is as follows.
There is also a reduction in explicit typecasting. Also, it supports the generic pointer type which makes it as a generic-purpose compiler. This is a guide to Void Pointer in C. Here we also discuss the definition and how does void pointer work in c? You may also have a look at the following articles to learn more —. Submit Next Question. Here is the syntax of void pointer. Here vp is a void pointer, so you can assign the address of any type of variable to it. A void pointer can point to a variable of any data type and void pointer can be assigned to a pointer of any type.
For example:. It simply doesn't work that way!. Before you dereference a void pointer it must be typecasted to appropriate pointer type. Let me show you what I mean. For example: In the above snippet void pointer vp is pointing to the address of integer variable a.
0コメント