F
fcvcnet
Hi,
This is c code , but the question is same to c++ £¨new/delete£©.
char* p = malloc(10);
strcpy(p, "hello");
printf("%s\n", p);
free(p);
// free just add p to the free list of memory, and do nothing else.
// Is there any use of p? If we never use p why not just nullify p in
free()?
p = NULL; // If we do not use p after call free , we can delete this line
..
And someone write p = NULL is not a good idea for Unix.
Thanks.
This is c code , but the question is same to c++ £¨new/delete£©.
char* p = malloc(10);
strcpy(p, "hello");
printf("%s\n", p);
free(p);
// free just add p to the free list of memory, and do nothing else.
// Is there any use of p? If we never use p why not just nullify p in
free()?
p = NULL; // If we do not use p after call free , we can delete this line
..
And someone write p = NULL is not a good idea for Unix.
Thanks.