Examveda

What will happens if the statement free(a) is removed in the following C code?
#include<stdio.h>
#include<stdlib.h>
main()
{
    int *a;
    a=(int*)malloc(sizeof(int));
    *a=100;
    printf("*a%d",*a);
    free(a);
    a=(int*)malloc(sizeof(int));
    *a=200;
    printf("a%p",a);
    *a=200;
    printf("a%d",*a);
}

A. Error

B. Memory leak

C. Dangling pointer arises

D. 200 is printed as output

Answer: Option B


This Question Belongs to C Program >> Memory Allocation

Join The Discussion

Related Questions on Memory Allocation