What is a void pointer? Can you dereference a void pointer without knowing its type? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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