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

How do you construct an increment statement or decrement statement in C?

0 Answers  


Write a pro-gramme to determine whether the number is even or odd?

1 Answers  


How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same

0 Answers   Amazon,


. Write a program to get a string and to convert the 1st letter of it to uppercase

2 Answers   HTC,


WHAT IS HEADER?

8 Answers   ProKarma, TCS,


what is a c-language.what is do.

4 Answers   HCL,


Go through this linked list concept.While traversing through the singly linked list sometimes the following code snippet "while(head != NULL)" is used and other times "while(head->link != NULL)"is used(Here head is the pointer pointing to the first node,node has two parts data part and link part).What is the difference between head != NULL and Head->link != NULL and in which situation are they used?

1 Answers   Oracle,


explain about storage of union elements.

2 Answers   ABC, Bosch,


how many errors in c explain deply

0 Answers  


What are preprocessor directives?

1 Answers  


What are the uses of a pointer?

0 Answers  


do ne body have any idea about the salary for the we r going to have interview. yup .. u got it right ..i m talking abt NIC.

1 Answers  


Categories