c - Pointer array assignments change pointer value directly -
there's multiple things might not potentially understand situation. i'm making own version of malloc, provided sbrk function gives me address use allocate memory on. address goes
void* heap = my_sbrk(stuff);
i need put acquired space can give out in array. since heap pointer points start of available space do
freelist[7] = heap;
now can implement function , works until does
freelist[7] = null;
which results in heap becoming null
more if want change pointer pointing beginning address of heap, point null instead, heap ends pointing @ null.
is problem memory allocation? problem me misunderstanding how pointers work?
edit: nothing 'duplicate question', poster wants understand how memory allocated. want understand why changing value of element of pointer array changes object element pointing to.
namely, if
int* array; int value = 8; int* pointer = &value; array[0] = pointer; array[0] = null;
i expect array[0] = null , *pointer = 8;
Comments
Post a Comment