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 is break in c?
difference between native and cross compilers
if a is an integer variable, a=5/2; will return a value a) 2.5 b) 3 c) 2 d) 0
Explain what is the advantage of a random access file?
Explain what is page thrashing?
What is extern variable in c with example?
Why is c known as a mother language?
What is structure of c program?
What is calloc()?
How can I write a function analogous to scanf?
How does placing some code lines between the comment symbol help in debugging the code?
What are the 4 types of organizational structures?
What is structure data type in c?
What does calloc stand for?
Explain how do you declare an array that will hold more than 64kb of data?