Why do we have pointers other than void

前端 未结 10 1005
攒了一身酷
攒了一身酷 2020-12-30 22:54

I know that we have different pointers like int, float, and char. A void pointer is the only pointer which can hold all o

10条回答
  •  忘掉有多难
    2020-12-30 22:54

    When You use pointer to float or int (for example) compiler knows how many bytes it should take from memory (sizeof(int) for int* for example).

    With void You would have to tell each time to compiler how many bytes it have to take (by writing (int*)some_void_ptr for example.

    But this is great simplification.

提交回复
热议问题