Could somebody tell me the difference between:
int *p;
p=(int*)malloc(10*sizeof(int));
free(p);
or
int *p;
p=(int*)malloc(10*sizeof(int));
p=NULL;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
freewill deallocate the memory thatppoints to – simply assigning it toNULLwill not (and thus you will have a memory leak).It is worth mentioning that it is good practice to assign your pointer to
NULLAFTER the call tofree, as this will prevent you from accidentally trying to access the freed memory (which is still possible, but absolutely should not be done).