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

Why is c so important?

0 Answers  


Write a program of prime number using recursion.

0 Answers   Aspiring Minds,


1.write a program to merge the arrays 2.write efficient code for extracting unique elements from a sorted list of array?

3 Answers   Qualcomm,


how to print "hai" in c?

13 Answers   TCS,


What is the difference between array_name and &array_name?

0 Answers  






Explain how can I make sure that my program is the only one accessing a file?

0 Answers  


WHO WROTE C LANGUAGE?

4 Answers  


What is unary operator?

0 Answers  


What are types of preprocessor in c?

0 Answers  


#include<std.h> int main() { char *str[]={"Frogs","Do","Not","Die","They","Croak!"}; printf("%d %d\n",sizeof(str),strlen(str)); ...return 0; } what will the output of the above program?

6 Answers  


Write a C program to convert an integer into a binary string?

1 Answers  


what are enumerations in C

0 Answers   TCS,


Categories