Relative Content

Tag Archive for cfree

Why is my pointer not null after free?

void getFree(void *ptr) { if(ptr != NULL) { free(ptr); ptr = NULL; } return; } int main() { char *a; a=malloc(10); getFree(a); if(a==NULL) printf(“it is null”); else printf(“not null”); } Why is the output of this program not NULL? c free 1 Because the pointer is copied by value to your function. You are assigning […]