# Include <stdio. h>
# Include <stdlib. h>
Int F ()
{
Return 0;
}
Int main (INT argc, char * argv [])
{
F (10); // if the function is int F (void), an error is returned.
Int * PI;
Void * PV;
Pi = PV;
Pv = PI;
// * Pv = 8; Error
// PV [0] = 4; Error
Int * P = (int *) malloc (100 * sizeof (INT ));
Free (P );
System ("pause ");
Return 0;
}
Under the C CompilerC does not perform parameter check on F (). Therefore, if F (10) is written in the main function, the compiler does not report an error.
Int F (void)
{
Return 0;
}
In this case, F (10) in the main function reports an error because void indicates that the compiler has no parameters.
Note: The C ++ compiler does not have any parameters by default. Whether you write int F () or Int F (void), an error is reported for F (10) in the main function.
The void * Table points to an uncertain object type. Void * can be directly transformed with any pointer, except for function pointers.
For example:
Int * PI;
Void * PV;
Pi = PV;// Note that PI = (int *) PV must be converted in the C ++ compiler;
Pv = PI;
Because void * can be directly transformed with any pointer, except for function pointers,Under the C Compiler, We know that the return type of the malloc function is void *, so the next two sentences are equivalent.
Int * P = (int *) malloc (100 * sizeof (INT ));
Int * P = malloc (100 * sizeof (INT ))
However, void * cannot be used for values or small tables.
// * Pv = 8; Error
// PV [0] = 4; Error