Dereference void pointer

前端 未结 7 1616
借酒劲吻你
借酒劲吻你 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:04

    It doesn't make sense to dereference a void pointer. How will the compiler interpret the memory that the pointer is pointing to? You need to cast the pointer to a proper type first:

    int x = *(int*)lVptr;
    

提交回复
热议问题