What is a void pointer? Can you dereference a void pointer without knowing its type? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 Answers
+ 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