Question:
why do we declare p2 as void **? why not p2*?
we are returning p2, but our return function type is void *. This doesn't make any sense. Compiler will say unmatch return type.
void *aligned_malloc(size_t required_bytes, size_t alignment) {
void *p1;
void **p2;
int offset=alignment-1+sizeof(void*);
p1 = malloc(required_bytes + offset); // the line you are missing
p2=(void**)(((size_t)(p1)+offset)&~(alignment-1)); //line 5
p2[-1]=p1; //line 6
return p2;
}