SNR SNR - 1 year ago 63
C Question

What is void* and to what variables/objects it can point to

Specifically, can it point to int/float etc.?
What about objects like NSString and the like?
Any examples will be greatly appreciated.

Answer Source

void* is such a pointer, that any pointer can be implicitly converted to void*.

For example;

int* p = new int;
void* pv = p; //OK;
p = pv; //Error, the opposite conversion must be explicit in C++ (in C this is OK too)

Also note that pointers to const cannot be converted to void* without a const_cast


const int * pc = new const int(4);
void * pv = pc; //Error
const void* pcv = pc; //OK


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download