Look at the code:
#include
#include
void main()
{
int *p;
p = malloc(6);
p = realloc(p, 10);
if (p == NULL)
{
pri
Correct -- if realloc
can't resize the memory block you pass in, it makes a new one, copies the data, and deallocates the old one.
HOWEVER:
malloc
implementations do not typically operate on a byte granularity. Most of the ones I've seen round everything up to the nearest 16 bytes, since it makes accounting easier, and many users will need that alignment anyway. In your case, this would end up making the realloc
a no-op, since both sizes round up to 16 bytes.
In most common multitasking operating systems, the only memory accessible to your application is its own -- other applications' memory will never get in your way. Memory allocated by libraries or other threads might, though.