If do the next:
int* array = malloc(10 * sizeof(int));
and them I use realloc:
array = realloc(array, 5 * sizeof(int));
The language (and library) specification makes no such guarantee, just like it does not guarantee that a "trimming" realloc
will preserve the pointer value.
An implementation might decide to implement realloc
in the most "primitive" way: by doing an unconditional malloc
for a new memory block, copying the data and free
-ing the old block. Obviously, such implementation can fail in low-memory situations.