hi;
do i need to use free with each malloc?
how could i free memory in this function:
Code:char *function(){
char * p=malloc(10*sizeof(char));
.......
....
return p;
}
Printable View
hi;
do i need to use free with each malloc?
how could i free memory in this function:
Code:char *function(){
char * p=malloc(10*sizeof(char));
.......
....
return p;
}
As a general rule you should.
It's also a 'guideline' to put the corresponding free() with it's malloc, but not possible in all cases, such as this.
Simply call free() on the pointer returned by 'function'.