What is the output of this program?
#include
#include
int main()
{
int *j = (int*)malloc(4 * sizeof(int));
*j = 15;
free(j);
printf("%d", *j);
return 0;
}
Answer: B
In this program, a pointer variable *j is declared and its memory space is allocated using malloc() and then an integer value 15 is set to a pointer variable *j. Now free(j) is used to free or delete the memory space allocated to the pointer variable *j using malloc(). While freeing the memory space allocated using malloc(), all allocated space will be deleted and by default the deleted space will be denoted by some garbage value and is outputted.