What is (void*) casting used for?

前端 未结 4 670
无人共我
无人共我 2021-02-09 12:29

I did try searching for this on Stack Overflow, but I think due to the syntax and not knowing exactly what to search I became a little unstuck.

I have seen (v

4条回答
  •  情歌与酒
    2021-02-09 12:52

    void*, usually referred to as a void pointer, is a generic pointer type that can point to an object of any type. Pointers to different types of objects are pretty much the same in memory and so you can use void pointers to avoid type checking, which would be useful when writing functions that handle multiple data types.

    Void pointers are more useful with C than C++. You should normally avoid using void pointers and use function overloading or templates instead. Type checking is a good thing!

提交回复
热议问题