Dereference void pointer

前端 未结 7 1612
借酒劲吻你
借酒劲吻你 2020-12-08 10:47

Even after casting a void pointer, I am getting compilation error while dereferencing it. Could anyone please let me know the reason of this.

int lVNum = 2;
         


        
7条回答
  •  不知归路
    2020-12-08 11:20

    printf("\nlVptr[60 ] is %d \n", *(int*)lVptr);

    This will cast the void pointer to a pointer to an int and then dereference it correctly.

    If you want to treat it as an array (of one), you could do a slightly ugly ((int *)lVptr)[0]. Using [1] is out of bounds, and therefore not a good idea (as for lVptr[60]...)

提交回复
热议问题