I want to pass a pointer to a variable. Sometimes it would be an integer and sometimes maybe a character. In the example below i pass the pointer p to CreateObject but when i try to retrieve the value of the variable the pointer points to i get an awkward result:
int i =0;
int *p = malloc(sizeof(int));
*p = i;
ObjectP object = CreateObject(p);
Say i want to cast it back to an int and display it:
void CreateObject(void *key)
{
printf("%d\n", (int)key);
}
I get: 160637064 instead of 0. What am i getting instead of the integer i assigned previously and how do i retrieve it instead of the current value?