What is a memory leak in structures? How can we rectify that?

Answers were Sorted based on User's Feedback



What is a memory leak in structures? How can we rectify that?..

Answer / 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

What is a memory leak in structures? How can we rectify that?..

Answer / sadhasivaraj

defining a structure includes lots of memory space bcoz
scructure consumes lots of memory space by allocatin a
desired space during initialization
ie bcoz struct can handle different data types

Is This Answer Correct ?    4 Yes 1 No

Post New Answer

More C Interview Questions

in which language c language is written?

2 Answers  


1.What is a Data Structure? Explain its need? 2.What is a Directed Graph? Write an algorithm to find whether a Directed Graph is connected or not? 3.Explain the process of converting a Tree to a Binary Tree.

4 Answers   Ignou, TCS,


What is the code for 3 questions and answer check in VisualBasic.Net?

0 Answers   Infosys,


write a function for strtok()??

2 Answers   Verifone,


Write a function to find the area of a triangle whose length of three sides is given

2 Answers  






What is the difference between printf and scanf in c?

0 Answers  


Identify the correct argument for the function call fflush () in ANSI C: A)stdout B)stdin C)stderr D)All the above

5 Answers   Accenture, TCS,


Differentiate between the expression “++a” and “a++”?

0 Answers  


What is hungarian notation? Is it worthwhile?

0 Answers  


What are reserved words?

0 Answers  


What is dynamic variable in c?

0 Answers  


What is the real difference between arrays and pointers?

27 Answers   Hexaware, Logic Pro, TCS,


Categories