Extern double * mat (int n, int m)
{
Double * p;
if (! (p=(double *) malloc (sizeof (double) * n * m)))
{
Fatalerr (" matrix memory allocation error: n=% d, m=% d \ n ", n, m);
}
return p;
}
//function
# include ", "
Void main () {
int a,b;
Double c;
A=3; B=3;
C=* mat (a, b);
Printf (" c=% f ", c);
getchar();
};
Small white consult everybody, the child function p point to release the memory? Release in a child function or in the calling routine release? What are the consequences if they don't release? If not release the end systems can be recycled?
CodePudding user response:
In theory the malloc to matching freeCodePudding user response:
External release so you now is notYou need a pointer variable to hold the return value
After finishing with free (pointer variable)
CodePudding user response:
As long as you keep the malloc return address, where the release of it doesn't matter, don't lose the address values make it ~