#include <stdio.h>
#include <stdlib.h>
//void * Can be any type of data, any type can be stored, or you can convert any type
int main () {
//Example 1: Assign the normal pointer variable to the void* pointer and print out the
int pa =;
int *p = &pa;
void * v = p;
printf ("v=%d \", * ((int*) v));
Example 2: Modifying the value of a variable by void* pointer
float f = 3.14f;
void *v2 = &f;
printf ("f=%.2f,v2=%.2f\n", f,* (float*) v2);/Output f=3.14,v2=3.14
* ((float*) v2) = 100.99f;//after
modifying values by void* pointer printf ("f=%.2f,v2=%0.2f\n", f,* (float*) v2));
Output f=100.99,v2=100.99
system ("pause");
return 0;
}
/*
Note: In the ANSI C standard, some arithmetic operations on void pointers, such as p++ or p+=1, are not allowed.
Because void is no type, we don't know how many bytes to operate on every arithmetic operation.
But GNU is not so determined, it specifies void * 's algorithm operation and char * consistent. The following statements are therefore correct in the GNU compiler:
pvoid++; GNU: Correct pvoid = 1; GNU: The correct pvoid++ result is that it's increased by 1
*/