一级指针强转成二级指针,如void*到char**,用一句话理解,就是把一级指针所指的内存强转成char*.
void main()
{void *p = malloc(20);
memset(p,0,20);
char **typed_p = (char **)p;
printf("p is 0x%08x\n",(unsigned int)p);
printf("typed_p is 0x%08x\n",(unsigned int)typed_p);
printf("typed_p[0] is 0x%08x\n",(unsigned int)typed_p[0]);
printf("typed_p[1] is 0x%08x\n",(unsigned int)typed_p[1]);
printf("&typed_p[0] is 0x%08x\n",(unsigned int)&typed_p[0]);
printf("&typed_p[1] is 0x%08x\n",(unsigned int)&typed_p[1]);
free(p);
p = NULL;
return;
}
运行结果:
p is 0x08460008
typed_p is 0x08460008
typed_p[0] is 0x00000000
typed_p[1] is 0x00000000
&typed_p[0] is 0x08460008
&typed_p[1] is 0x0846000c