0

void*

What means void* in c++? How can pointer point at nothing?

23rd Dec 2017, 9:55 PM
Petr Leliaev
Petr Leliaev - avatar
3 Answers
+ 2
Void pointers​ come from c. They are useful because they allow you to make a function that uses pointers to different types. (There are no template functions​ in c.) qsort is a good example of this, you can pass it an int pointer, or char pointer, etc. Then qsort can sort an array of integers or char etc. Also malloc uses void pointers so you can allocate memory for any type.
24th Dec 2017, 1:26 AM
Jared Bird
Jared Bird - avatar
0
@Ace thank you! And how can we use it? I can not understand a prototype of qsort from cstdlib, but, perhaps, there is a less difficult example.
24th Dec 2017, 12:34 AM
Petr Leliaev
Petr Leliaev - avatar
0
Thank you all, it wasn't clear for me for a few years))
24th Dec 2017, 5:53 PM
Petr Leliaev
Petr Leliaev - avatar