天天看點

【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;
}      

  代碼測試結果

【C/C++】void指針知多少

QQ聯系方式:[email protected]

【C/C++】void指針知多少

出處:lcw.cnblogs.com

郵箱:[email protected]

本文申明:本文版權歸作者和部落格園共有,歡迎轉載,轉載請注明出處.