Void pointer conversion and void pointer Conversion
Pointers of any type can be explicitly converted to void without data loss. For example:
# Include <stdio. h>
Int main (void)
{
Short a = 5;
Void * p1;
Short * p2;
P1 = (void *) &;
P2 = (short *) p1;
Printf ("% d \ n", * p2 );
Return 0;
}
The address of a is 0x0012ff7c. Therefore, the address 0x0012ff7c is stored in p1, and its data is 5, but 5 cannot be accessed through p1. If you want to access data, you can use Explicit conversions to convert p1 to the short type (data 5 itself is the short type), that is, p2. In this case, you can call p2 to access data 5 without data loss.
In the above case, the pointer format of the same length is converted to each other, and its size remains unchanged, and the data will not be distorted.
If a void pointer is forcibly converted to int and then to long, the size will change and the data will also be distorted.