Freeing strings in C
If I would write:
Free an assigned pointer
Does the following code free the memory that was allocated for x
?
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 […]
C – Does freeing an array of pointers also free what they’re pointing to?
Say I have an array of pointers to structs that contain a string each and so for something like this: