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
How can I delete a file?
What is the general form of #line preprocessor?
What is the difference between break and continue?
Why is sprintf unsafe?
Is boolean a datatype in c?
Why C language is a procedural language?
Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.
Can a variable be both constant and volatile?
which of the following statement is wrong a) mes=123.56; b) con='T'*'A'; c) this='T'*20; d) 3+a=b;
How can I make it pause before closing the program output window?
What is the use of a ‘ ’ character?
Why doesnt long int work?
Is flag a keyword in c?
What are the 4 types of organizational structures?
Write a C program to count the number of email on text