Sunday 21 January 2018

c - freeing memory using free()

I want to understand free() in c deallocates memory or it
simply erases the data in the allocated memory by
malloc.



#include
#include

int
main()
{
int n;
printf("enter the size of
n:\n");
scanf("%d", &n);

int*
A=(int*)malloc(5*sizeof(int));
int i;
for(i=0; i i++)
{
printf("%d\n", &A[i]);

}

free(A);


printf("\n\n-------------\n\n");


for(i=0; i i++)
{

printf("%d\n", &A[i]);

}

return
0;
}



Still
after freeing A its giving the same address of A.
What free() actually
do?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...