in
void delete(node* list){
list=NULL;
//printf(list); prints the expected output: []
}
you set only the local variable (ie: parameter) list
to be null, this does not affect the x
from the outside world.
firstly, you should:
void delete(node** list){
*list=NULL;
}
to set the x
from main to NULL... however this does not FREE your list, the memory is still there and allocated (memory leak). You need to walk through the list and free all elements... this is your homework :)
Offtopic: Yes, I know this is C
... however calling a function delete
is asking for trouble when this will be compiled with a C++
compiler ... tell this to your teacher. delete
is a reserved keyword.