What is a memory leak in structures? How can we rectify that?
Answer Posted / selvaraj
unwanted memory consumed by a program is called memory leak.
Example:
int fact(void)
{
size=melloc(20);
if(size==NULL)
{
return 1;
}
else
{
return 0;
}
}
Explanation:
size=melloc(20);
here the memory reserved
if(size==NULL)
if memory not available
else means memory available return 0
so, throughout the program the size never used but the program reserved the size. this is called memory leak..
to over come this problem in the else part before return 0; add this statement free(s)
Hope you understood. if not u can reach me iamselvam85@gmail.com
| Is This Answer Correct ? | 13 Yes | 2 No |
Post New Answer View All Answers
What will the code below print when it is executed? int x = 3, y = 4; if (x = 4) y = 5; else y = 2; printf ("x=%d, y=%d ",x,y);
What does %c mean in c?
Explain with the aid of an example why arrays of structures don’t provide an efficient representation when it comes to adding and deleting records internal to the array.
What is nested structure with example?
What is use of null pointer in c?
What is the difference between single charater constant and string constant?
How will you find a duplicate number in a array without negating the nos ?
What is pointers in c with example?
What is a good data structure to use for storing lines of text?
What is the advantage of c?
Can we increase size of array in c?
Is sizeof a keyword in c?
Why is c so important?
Explain how do you determine the length of a string value that was stored in a variable?
What are the features of c languages?