Assuming that I have allocated memory using malloc()
, if I do in my code:
char *newline = realloc ( oldline , newsize );
// Assuming oldline is the pointer to which the starting address
// of the memory which malloc() has returned, is assigned and,
// say, newsize is integer having 100 value.
Now my questions regarding it are:-
- Is it necessary that
newline
will point to same address asoldline
, which holds the previous initial address? - Is it so that in this case,
oldline
will be freed(implicitly) andnewline
will take the charge of memory addressing? After the above code and after the work has been done, what should I do to free memory
free(newline);
or
free(oldline);
or both?
man realloc
and all your questions will be answered. On other OS's you need to figure out where the documentation is. – Lennox