c - I allocate memory in function, and return char*, how should I free it? -
if want allocate memory in function:
char* allocate() { char *cp = (char*)malloc(10); ... return cp; }
can use returned content in cp
main()
? , how free cp
?
can use returned content in cp in main()?
yes, can.
and how free cp?
using
free(cp); // replace cp name of pointer if using in function
also, should not cast result of
malloc
(and family) in c
Comments
Post a Comment