Sunday, 2 October 2016

Interview Question #1

What happens if you Call a free on a pointer twice?

Deallocating a memory area with free does not make the contents of the pointer NULL. 

Suppose that you have int *a = malloc (sizeof (int)) and a has 0xdeadbeef and you execute free (a) then after execution a still contains 0xdeadbeef but after the free call this memory address is no more reserved for you. 

Something like you have rented a flat with malloc used for some time, returned the flat by free then you might have a duplicate key for the flat, but it is not reserved for you.

Doing a free on an already freed memory will result in double free memory corruption.


Answer Original Source: StackOverFlow

Other Articles:
Kth smallest element , Merge Point In LinkListCompare two String Represented in Link-List

Article Sources For Learning

Other Blogs: Follow here


Post a Comment