【C/C++】void指针知多少
void指针
void指针平时用的地方不多,但是不代表它不重要
#include <stdio.h> typedef int*(*TY)[5]; //指针数组的指针类型 int main(void) { void *p1,*p2,*p3; int a1 = 100; int *px = &a1; //一级指针 int **py = &px; //二级指针 int a[5] = {1,2,3,4,5}; int *b[5] = {a,a+1,a+2,a+3,a+4}; //指针数组 p1 = &py; p2 = b; p3 = &b; printf("***(int***)p1 = %d \n",***(int***)p1); printf("**((int**)p2 + 1)) = %d \n",**((int**)p2 + 1)); printf("(((int**)p2)[1][0]) = %d \n",((int**)p2)[1][0]); printf("(*(TY)p3)[1][0] = %d \n",(*(TY)p3)[1][0]); printf("**(*(TY)p3 +1) = %d \n",**(*(TY)p3 +1)); return 0; }
代码测试结果