memory management between functions
Dan Bernstein
brnstnd at kramden.acf.nyu.edu
Tue Apr 30 01:34:09 AEST 1991
In article <8504 at umd5.umd.edu> jjk at astro.umde.edu (Jim Klavetter) writes:
> for(i=0; i<n; i++)
> c[i]=a[i]-b[i];
> free(c);
> return(c);
A pointer is just an address. The pointer variable c holds the address
of a malloc'ed array. When you blow away the array, c's address is out
of date, and once the array elements are dead and buried the postmaster
can't forward your mail (c[i]) to the cemetery.
---Dan
More information about the Comp.lang.c
mailing list