Free memory or garbage in recursion program
** Free memory or garbage in recursion program
** Here, i have maked a simple recursion program. It's parametter is
** an integer called i.
** If i = 5 then return 1, else return i * Recursion(i+1). It is
** very simple, we will not say about the mean of this program.
** The more important, int Recursion function i created a j varible
** and when the program finished, i want to release memories pointed
** by pointer j. I don't know how. Can you help me.
** I want to know your idea and don't change my idea in this funny
** I think we always met this problem.
** Good luck to all of you !
int Recursion( int* i)
if ( *i == 5 )
int *j = 0;
j = (int*) malloc(sizeof(int));
*j = *i+1;
return (*i * Recursion( j ));
int i = 1;
int k = Recursion( &i );
printf("%d",k); // return 24
By Preet Kanwaljit Singh in forum Careers
Last Post: 07-14-2003, 03:08 PM
By smrutideep in forum Careers
Last Post: 03-20-2003, 12:39 AM
Last Post: 12-15-2000, 11:07 PM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center