N
new
Hi all,
I need your suggestions/comments on the code snip below.
<< snip >>
typedef struct rose {
int k;
char c;
}my_red;
boolean fun(my_red **x,int i)
{
my_red *c=NULL;
c= malloc(sizeof(my_red));
if(!c)
return FALSE;
c->k = i;
*x = c;
return TRUE;
}
int main(void)
{
my_red *ptr = NULL;
if( ! fun(&ptr,9))
printf("Error");
else
printf("k= %d",*ptr);
return 0;
}
<< End Snip >>
Now my question is how to free memory block allocated to variable c in
fun() being in main() function.Does freeing the ptr variable frees the
memory block? If so how?
Thanks a lot in advance.
I need your suggestions/comments on the code snip below.
<< snip >>
typedef struct rose {
int k;
char c;
}my_red;
boolean fun(my_red **x,int i)
{
my_red *c=NULL;
c= malloc(sizeof(my_red));
if(!c)
return FALSE;
c->k = i;
*x = c;
return TRUE;
}
int main(void)
{
my_red *ptr = NULL;
if( ! fun(&ptr,9))
printf("Error");
else
printf("k= %d",*ptr);
return 0;
}
<< End Snip >>
Now my question is how to free memory block allocated to variable c in
fun() being in main() function.Does freeing the ptr variable frees the
memory block? If so how?
Thanks a lot in advance.