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

Explain what is meant by high-order and low-order bytes?

0 Answers  


How to set file pointer to beginning c?

0 Answers  


Eight queens puzzle

0 Answers  


What is null pointer in c?

0 Answers  


#define MAX 3 main() { printf("MAX = %d ",MAX ); #undef MAX #ifdef MAX printf("Vector Institute”); #endif }

1 Answers  






program for following output using for loop? 1 2 3 4 5 2 3 4 5 3 4 5 4 5 5

8 Answers   Infosys,


What are void pointers in c?

0 Answers  


while initialization of array why we use a[][2] why not a[2][]...?

0 Answers   Aptech,


write a function that accepts an array A with n elements and array B with n-1 elements. Find the missing one in array B,with an optimized manner?

2 Answers   Zensar,


Write a c program using for loop to print typical pattern if number of rows is entered by keyboard. ABCBA AB BA A A

1 Answers  


What are the types of type qualifiers in c?

0 Answers  


Explain about the functions strcat() and strcmp()?

0 Answers  


Categories