[Reprint] http://blog.csdn.net/mhjcumt/article/details/7355127
Int a = 1;
Int * p = &;
Float * p1 = (float *) p;
The values of p and p1 are both & a, but * p interprets the values in & a according to the int type variable, * p1 interprets the value in & a according to the float variable.
Given the need for flexible forced type conversion between pointers and the need for simplified code, ansi c introduces a null pointer, namely void *. Void pointers are also called Universal pointers. In many programs, they are replaced by universal pointers when the parameters are uncertain. Such pointers are particularly common in thread/process functions.
Ansi c stipulates that the void pointer can be copied to any type of pointer, and other types of pointers can also be copied to the void pointer. The forced type conversion is not required for copying between them. Of course, any address can also be copied to the void pointer. We often see accept (socket,
(Struct sockaddr *) & saddr_c, & lenth) You need to add code (struct
Sockaddr *) is because when this function is designed, ansi c has not introduced the concept of void. All addresses use struct
Sockaddr type identifier. The second parameter of this function is also a pointer to the struct sockaddr type, which is forced type conversion.
Of course, in some compilers, pointers of different types can also be directly assigned values, but in general, a warning of Type mismatch is given. Requiring the programmer to display a pointer to force type conversion can remind the programmer to use the pointer with caution, which has certain benefits for clarifying the purpose of the program.