I have the following code:
int** x;
// Add 4 int pointers to x - code ommitted
// Pop the first element
int* a = x[0];
memmove(&x[0], &x[1], sizeof(int*) * 3);
x = realloc(x, sizeof(int*) * 3);
// Some code that uses 'a' - ommitted
As per my understanding a
is now pointing at the first location x
points to. But that memory location now actually contains the data that was previously on x[1]
due to the memmove
.
Looking at how this code is used, it seems that a
should actually point to the value that was previously on x[0]
. My question is, how is it possible for a
to contain that previous value if that memory location has been now replaced by what was in x[1]
?