This isn't trivial to do, but here's the simplest way to do it:
You need to know all the types you'll support, and what they are when you insert them.
First, you'll actually have a data structure of some struct like
struct { void * data; enum Type tag }
and define an enum Type { int, char*, ... etc }
The void *
is a pointer to data without a type, so you can use it to store to a chunk of memory that contains the data you want to store.
The Type tag stores what the data is so that your code using it can know what is being returned from your data structure.
If you don't need to store the type, and you can cast it back to the correct type when you pull it out of your data structure, then you can omit the Type tag and just store void *