C | Dynamic Memory Allocation | Question 7

Last Updated :
Discuss
Comments
What is the problem with following code? C
#include<stdio.h>
int main()
{
    int *p = (int *)malloc(sizeof(int));

    p = NULL;

    free(p);
}
Compiler Error: free can\'t be applied on NULL pointer
Memory Leak
Dangling Pointer
The program may crash as free() is called for NULL pointer.
Tags:
Share your thoughts in the comments