Casting void pointers

前端 未结 4 1282
抹茶落季
抹茶落季 2020-12-03 10:31

I\'ve seen a lot of the following in older C code:

type_t *x = (type_t *) malloc(...);

What\'s the point of casting the pointer returned fr

4条回答
  •  醉梦人生
    2020-12-03 11:18

    What's the point of casting the pointer returned from malloc() since it's void *?

    Quite the contrary. You need to cast a void pointer to an actual type before you can use it, because a void * signifies nothing about the data stored at that location.

提交回复
热议问题