// MEMORY ALLOCATION
//TOPIC : free() - - DEALLOCATION
// FIRST COPY PASTE ANY malloc() or calloc() PROGRAM
int main()
{
int i,n,*p;
printf("\n Enter the Number of Elements : \n");
scanf("%d",&n);
// MEMORY ALLOCATION USING CALLOC() FUNCTION
p=(int*)calloc(n,sizeof(int));
// TO PRINT THE ADDRESS OF MEMORY LOCATION
for(i=0;i lt n;i++)
{
printf("\nAddress of Location %d is :::::: \t %d\n",i,&p[i]);
}
// TO GET ELEMENTS FROM USER
for(i=0;i lt n;i++)
{
printf("\nEnter the Element \n");
scanf("%d",&*(p+i));
}
//PRINT THE ELEMENTS
printf("\n::::The Elements in Memory Location ::::");
for(i=0;i lt n;i++)
{
printf("\n%d\n",*(p+i));
}
// DEALLOCATION STARTS HERE
// USE FREE() FUNCTION ALONG WITH POINTER VARIABLE
free(p);
//NOW TRY TO PRINT THE ELEMENTS HERE
printf("\n::::The Elements in Memory Location AFTER DEALLOCATION::::");
for(i=0;i lt n;i++)
{
printf("\n%d\n",*(p+i));
}
// free function will release all memory
// OLDER VALUES WILL BE REPLACED BY GARBAGE VALUES
return 0;
}
On this page of the site you can watch the video online MEMORY ALLOCATION - free() with a duration of hours minute second in good quality, which was uploaded by the user Solution Manual 16 April 2020, share the link with friends and acquaintances, this video has already been watched 7 times on youtube and it was liked by 0 viewers. Enjoy your viewing!