关于void * 的注意事项
1:void 在函数前面代表函数没有返回值。
2:void* 做函数的参数,表示任何类型指针都可以不经过强制转换就可以直接传入
3: 在函数中接受到void *类型的指针,必须要强制转换成需要的类型指针,才可以使用
1 #include<stdio.h>
2
3 void fun(void *p1)
4 {
5 int *p2 = (int *)p1;
6 printf("this is : %d\n" , *p2);
7
8 }
9
10 void fun1(void *p1)
11 {
12 char *p2 = (char *)p1;
13 printf("this is : %c\n" , *p2);
14
15 }
16
17 int main(int argc, char *argv[])
18 {
19 int p = 10;
20 char c = 'a';
21 printf("test \n");;
22 fun(&p);
23 fun1(&c);
24 return 0;
25
26
结果
test
this is : 10
this is : a