I have an array of arbitrary values, so I have defined it as an array of void pointers, so I can point to any kind of information (like int
, character arrays, etc). However, how do I actually assign an int
to it?
Take for example these initializations:
void* data[10];
int x = 100;
My intuition would think this, but this gives a compile error:
data[0] = malloc(sizeof(int));
*(data[0]) = x;
Also I thought about using &x
, but I would take the address of a local variable, which (to my understanding) would be cleared after exiting from the procedure. So if I have a local variable x
, how would I get it into a void pointer type of variable correctly?