I have a question about the following code:
int age = 20;
void * pointer;
pointer = alloc(sizeof(int), 0)
pointer = (void*) age;
How does it work?
What is the value of pointer?
What happens with this piece of code in terms of the line :
pointer = (void*) age;
This code accomplishes exactly nothing.
First, you allocated a pointer for a size of
int, using non-standard allocation methods.Then, you assign that pointer to point to the address 0x14, which probably doesn’t contain any valid information, and would give you a SEGFAULT if you attempted to dereference it.
Third, you leak the initial memory you
alloc‘d for pointer, which is never a good thing.Overall, a VERY bad design pattern.