+ 1

What is a void pointer? Can you dereference a void pointer without knowing its type?

18th Sep 2020, 11:08 AM
Pranjal Rastogi
Pranjal Rastogi - avatar
2 RĂ©ponses
+ 1
You cannot. Dereferencing a void pointer requires an explicit cast beforehand. You canofcourse cast it to any particular type and then dereference it without knowing itsoriginal type, but why you would want to do that is beyond me. From https://stackoverflow.com/questions/36931660/can-we-dereference-a-void-pointer-without-knowing-its-type
18th Sep 2020, 11:12 AM
👑FabVab👑
👑FabVab👑 - avatar
0
void pointer is also called generic pointer in C. It can hold an address of any type. You can't dereference it directly. You have to cast it for instance, *(int*)vptr
18th Sep 2020, 11:19 AM
äœ çŸ„é“èŠć‰‡ïŒŒæˆ‘äčŸæ˜Ż
äœ çŸ„é“èŠć‰‡ïŒŒæˆ‘äčŸæ˜Ż - avatar