void pointer in C / C++
A void pointer is a pointer that has no associated data type with it. A void pointer can hold address of any type and can be typcasted to any type. ... In C++, we must explicitly typecast return value of malloc to (int *).
Can we typecast void into int *?
You're return ing the value of int sum by setting a void * address to it. In this case, the address is not valid. But, if you keep that in mind and get the value of sum by casting a void * to int it will work.
How do I convert a void to int?
“convert void * to int” Code Answer's
- int a = 5;
- void *p = (void *)a;
- int b = (int)p;